1
1 import itertools 2 3 4 b = list(itertools.chain('ABC', range(2), [55,434,665,86])) 5 print('b:', b) # ['A', 'B', 'C', 0, 1, 55, 434, 665, 86] 6 7 b1 = list(enumerate("ABC")) 8 print('b1:',b1) # [(0, 'A'), (1, 'B'), (2, 'C')] 9 10 b2 = list(itertools.chain(enumerate("ABC"))) 11 print("b2:", b2) # [(0, 'A'), (1, 'B'), (2, 'C')] 12 13 b3 = list(itertools.chain.from_iterable(enumerate('ABC'))) 14 print('b3:', b3) #[0, 'A', 1, 'B', 2, 'C'] 15 16 17 b4 = list(zip('ABC', range(5))) 18 print('b4:', b4) # [('A', 0), ('B', 1), ('C', 2)] 19 20 21 b5 = list(itertools.zip_longest('ABC', range(5))) 22 print('b5:', b5) #[('A', 0), ('B', 1), ('C', 2), (None, 3), (None, 4)] 23 24 25 b6 = list(itertools.zip_longest('ABC', range(5), fillvalue = '?')) 26 print('b6:', b6) #[('A', 0), ('B', 1), ('C', 2), ('?', 3), ('?', 4)]
1
标签:ABC,函数,生成器,list,range,itertools,库中,print From: https://www.cnblogs.com/bravesunforever/p/17417584.html