用shuffle给列表洗牌

KongYun    2018-01-22 21:49

import random
dessert=['ice cream','pancake','brownies','cookies','candy']
random.shuffle(dessert)
print(dessert)

运行结果如下:

列表打印出来是洗牌后的结果,顺序完全不一样。如果写一个牌类游戏,可以用这个功能来对一个代表一副牌的列表洗牌。、

Views: 1.3K

[[total]] comments

Post your comment
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]Floor
  2. Click to load more...
  3. Post your comment