[Python] 纯文本查看 复制代码
import random
pokers = ['黑A', '黑K', '黑Q', '黑J', '黑0', '黑9', '黑8', '黑7', '黑6', '黑5', '黑4', '黑3', '黑2', '红A', '红K', '红Q', '红J', '红0', '红9', '红8', '红7', '红6', '红5', '红4', '红3', '红2', '梅A', '梅K', '梅Q', '梅J', '梅0', '梅9', '梅8', '梅7', '梅6', '梅5', '梅4', '梅3', '梅2', '方A', '方K', '方Q', '方J', '方0', '方9', '方8', '方7', '方6', '方5', '方4', '方3', '方2']
poker1 = [ ]
poker2 = [ ]
poker3 = [ ]
poker4 = [ ]
n = 0
random.shuffle(pokers)
for poker in pokers:
print(poker, end = ' ')
n +=1
if n in (13, 26, 39, 52):
print('\n')
print('...................................................'+'\n')
poker1 = pokers[0:13]
poker2 = pokers[13:26]
poker3 = pokers[26:39]
poker4 = pokers[39:52]
Hua={'黑':4,'红':3,'梅':2,'方':1}
shu={'A':14,'K':13,'Q':12,'J':11,'0':10,'9':9,'8':8,'7':7,'6':6,'5':5,'4':4,'3':3,'2':2}
poker1.sort(key=lambda k:(Hua[k[0:1]],shu[k[1:]]),reverse=True) #使用sort给poker1排序
poker2.sort(key=lambda k:(Hua[k[0:1]],shu[k[1:]]),reverse=True)
poker3.sort(key=lambda k:(Hua[k[0:1]],shu[k[1:]]),reverse=True)
poker4.sort(key=lambda k:(Hua[k[0:1]],shu[k[1:]]),reverse=True)
for poker in poker1:
print(poker + ' ',end ='') #print()里面加参数end =''即可实现不换行
print('\n')
for poker in poker2:
print(poker + ' ',end ='')
print('\n')
for poker in poker3:
print(poker + ' ',end ='')
print('\n')
for poker in poker4:
print(poker + ' ',end ='')
print('\n')