37,737
社区成员
发帖
与我相关
我的任务
分享In [80]: import itertools
In [81]: def power_sets(things):
...: return itertools.chain.from_iterable(itertools.combinations(things, m)
...: for m in range(2, len(things)+1))
In [82]: def combine_chars(char_lists):
...: return itertools.chain.from_iterable(itertools.product(*sets)
...: for sets in power_sets(char_lists))
In [83]: k = list(combine_chars([a, b, c]))
In [84]: k[20:30]
Out[84]:
[('c', '0'),
('c', '1'),
('c', '2'),
('c', '3'),
('c', '4'),
('c', '5'),
('c', '6'),
('c', '7'),
('c', '8'),
('c', '9')]
In [85]: k[-10:]
Out[85]:
[('h', '9', 'I'),
('h', '9', 'J'),
('h', '9', 'K'),
('h', '9', 'M'),
('h', '9', 'L'),
('h', '9', 'N'),
('h', '9', 'O'),
('h', '9', 'P'),
('h', '9', 'Q'),
('h', '9', 'R')]
['a0', 'b1', 'c2', 'd3', 'e4', 'f5', 'g6', 'h7']
['aI', 'bJ', 'cK', 'dM', 'eL', 'fN', 'gO', 'hP']
['0I', '1J', '2K', '3M', '4L', '5N', '6O', '7P', '8Q', '9R']
a = ['a','b','c','d','e','f','g','h']
b = ['0','1','2','3','4','5','6','7','8','9']
c = ['I','J','K','M','L','N','O','P','Q','R']
def getStr(a,b):
val = []
for i in zip(a,b):
val.append(''.join(i))
return val
print(getStr(a,b))
print(getStr(a,c))
print(getStr(b,c))