Python 随机-字符串列表切片练手

Posted on 2018-03-27 23:31  一入iT深似海  阅读(271)  评论(0编辑  收藏  举报
#conding:utf-8
#作者:不二哥哥
import random

poker_num = [i for i in range (2,11)]
# print(poker_num)
poker_str = ["A","J","Q","K"]
poker_king = ["大王","小王"]

poker_color=["红","黑","梅","方"]

# 生成扑克54张
pokers = ["%s%s" %(i,j) for i in  poker_color for j in poker_num+poker_str ]+poker_king
# print(pokers)

# 洗牌
random.shuffle(pokers)
print(len(pokers),pokers)
persona = pokers[0:51:3]
personb = pokers[1:51:3]
personc = pokers[2:51:3]
last_poker = pokers[-3:]
print("地主牌",last_poker)

#判断有红2是地主
if '红2' in persona:
  persona = persona+last_poker
elif '红2'  in personb:
  personb = personb+last_poker
else:
  personc = personc+last_poker

#打印每个人的牌 及张数
print("persona",persona,len(persona))
print("personb",personb,len(personb))
print("personc",personc,len(personc))