Join A List Of Tuples
My code looks the following: from itertools import groupby for key, group in groupby(warnstufe2, lambda x: x[0]): for element in group: a = element[1:4] b = e
Solution 1:
Use itertools.chain()
and list unpacking:
>>> items = [[('a','b','c'),('d','e','f')], [('g','h','i'),('j','k','l')]]
>>>
>>> list(chain(*items))
[('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'h', 'i'), ('j', 'k', 'l')]
Solution 2:
Try This
from itertools import groupby
result= []
for key, groupin groupby(warnstufe2, lambda x: x[0]):
for element ingroup:
a = element[1:4]
b = element[4:12]
c = [a,b]
result.append(c)
print (result)
Post a Comment for "Join A List Of Tuples"