问题遇到的现象和发生背景
['♣7', '♠7', '♣6', '♦5', '♣Q', '♥10', '♥A', '♣5', '♣9', '♣K', '♦4', '♦8', '♦Q']
['♦J', '♠8', '♣6', '♥3', '♥7', '♣5', '♣2', '♣6', '♣10', '♦A', '♦5', '♦9', '♠7']
['♣6', '♣2', '♦J', '♥4', '♥8', '♥Q', '♦A', '♣7', '♣J', '♦2', '♦6', '♦10', '♥4']
['♠7', '♠10', '♣Q', '♥5', '♦4', '♦8', '♣4', '♣8', '♣Q', '♦10', '♦7', '♦J']
4个列表分别如上
问题相关代码,请勿粘贴截图
import random
import numpy as np
rn=np.random.randint(1,55,54)
list_number=['3','4','5','6','7','8','9','10','J','Q','K','A','2',]
list_spade_label=['♠']*13
list_heart_label=['♥']*13
list_clubs_label=['♣']*13
list_diamonds_label=['♦']*13
def poker(label):
n=0
list1=[]
for i in label:
if n==13:
n=0
else:
list1.append(i+list_number[n])
n+=1
return list1
list_all_label=list_spade_label+list_heart_label+list_clubs_label+list_diamonds_label
list_all=poker(list_all_label)
if __name__ == '__main__':
hand=0
n=1
p1=[]
p2=[]
p3=[]
p4=[]
dict_all=dict(zip(rn,list_all))
for i in rn:
if n==4*hand+1 and dict_all.get(i)!=None:
n+=1
p1.append(dict_all.get(i))
elif n==4*hand+2 and dict_all.get(i)!=None:
n+=1
p2.append(dict_all.get(i))
elif n==4*hand+3 and dict_all.get(i)!=None:
n+=1
p3.append(dict_all.get(i))
elif n==4*hand+4 and dict_all.get(i)!=None:
n+=1
p4.append(dict_all.get(i))
hand+=1
print(p1)
print(p2)
print(p3)
print(p4)
我想要达到的结果
按平时打牌的习惯从小到大排序