# 如何取元祖里value的key，从最大value开始每5个key为一组保存到列表里，每组不相同，每组里的元素也不相同

tuple = {‘A’: 17, ‘B’: 22, ‘C’: 21, ‘D’: 9, ‘E’: 18, ‘F’: 17, ‘G’: 15, ‘H’: 21, ‘I’: 22, ‘J’: 21, ‘K’: 15, ‘L’: 19,
‘N’: 13, ‘M’: 20, ‘O’: 17, ‘P’: 11, ‘Q’: 21, ‘R’: 16, ‘S’: 16, ‘T’: 14, ‘U’: 11, ‘V’: 23, ‘W’: 12, ‘X’: 19, ‘Y’: 19, ‘Z’: 25}

``````letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def leeters_5():
for a in range(26-4):
for b in range(a+1,26-3):
for c in range(b+1,26-2):
for d in range(c+1,26-1):
for e in range(d+1,26):
yield [letter[a],letter[b],letter[c],letter[d],letter[e]]
l = leeters_5()
count = 0
for i in l:
# print(i)
count +=1
print(count)``````
1个月前 评论
LiTtianS （楼主） 1个月前

``````from pprint import pprint

a = {
'A': 17, 'B': 22, 'C': 21, 'D':  9, 'E': 18, 'F': 17, 'G': 15, 'H': 21,
'I': 22, 'J': 21, 'K': 15, 'L': 19, 'M': 20, 'N': 13, 'O': 17, 'P': 11,
'Q': 21, 'R': 16, 'S': 16, 'T': 14, 'U': 11, 'V': 23, 'W': 12, 'X': 19,
'Y': 19, 'Z': 25,
}

b = sorted(a.keys(), reverse=True, key=lambda x:a[x])
c = [tuple(b[i:i+5]) for i in range(0, len(b), 5)]

pprint(c)``````
``````[('Z', 'V', 'B', 'I', 'C'),
('H', 'J', 'Q', 'M', 'L'),
('X', 'Y', 'E', 'A', 'F'),
('O', 'R', 'S', 'G', 'K'),
('T', 'N', 'W', 'P', 'U'),
('D',)]``````
1个月前 评论
LiTtianS （楼主） 1个月前
Jason990420 （作者） 1个月前

1个月前 评论

``````from pprint import pprint
from itertools import combinations

a = {
'A': 17, 'B': 22, 'C': 21, 'D':  9, 'E': 18, 'F': 17, 'G': 15, 'H': 21,
'I': 22, 'J': 21, 'K': 15, 'L': 19, 'M': 20, 'N': 13, 'O': 17, 'P': 11,
'Q': 21, 'R': 16, 'S': 16, 'T': 14, 'U': 11, 'V': 23, 'W': 12, 'X': 19,
'Y': 19, 'Z': 25,
}

b = sorted(a.keys(), reverse=True, key=lambda x:a[x])
c = list(map(lambda x:'-'.join(x), combinations(b, 5)))

print(len(c))
pprint(c[::len(c)//10])``````
``````65780
['Z-V-B-I-C',
'Z-C-R-P-U',
'V-B-H-L-N',
'V-Q-X-G-T',
'B-H-J-W-U',
'I-C-L-T-D',
'C-H-J-M-A',
'H-J-E-A-U',
'J-X-O-R-K',
'M-F-S-W-D']``````

1个月前 评论
LiTtianS （楼主） 1个月前

1个月前 评论

1个月前 评论
LiTtianS （楼主） 1个月前

``````letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def leeters_5():
for a in range(26-4):
for b in range(a+1,26-3):
for c in range(b+1,26-2):
for d in range(c+1,26-1):
for e in range(d+1,26):
yield [letter[a],letter[b],letter[c],letter[d],letter[e]]
l = leeters_5()
count = 0
for i in l:
# print(i)
count +=1
print(count)``````
1个月前 评论
LiTtianS （楼主） 1个月前