1.
zip(*(iter(range(10)),) * 3)
Or
The difference between izip_longest (* (ITER (range (10),) * 3) Is that izip_longest places the last group that does not satisfy the group in the last element.
2. L = range (10) [L [I: I + N] For I in range (0, Len (L), n)] # split the list by N
3:for key, group in itertools.groupby(range(10), lambda k: k//3):
print key, list(group)
Grouping based on conditions that the key value meets
4:map
map(None, *[iter(range(10))] *3)
* 3 repeats the object three times.
Use asterisks * or ** when calling a function **
Test (* ARGs): * transmits each element in the ARGs sequence as a location parameter. If ARGs is equal to (1, 2, 3), the code is equivalent to test (1, 2, 3 ).
Test (** kwargs): ** converts the dictionary kwargs into a keyword parameter for transmission. If kwargs equals {'A': 1, 'B': 2, 'C': 3}, this code is equivalent to test (a = 1, B = 2, C = 3 ). * [Iter (range (10)] * 3 here is equivalent to <listiterator object at 0x17d76d0>, <listiterator object at 0x17d76d0>, <listiterator object at 0x17d76d0>, remove the list, send three values directly to map.
Map (none, * [iter (range (10)] * 3) is equivalent to map (none, <listiterator object at 0x17d76d0>, <listiterator object at 0x17d76d0>, <listiterator object at 0x17d76d0>)