Reputation: 3502
I have this data structure:
[((u'die', u'die'), (u'welt', u'WELT')),
((u'welt', u'WELT'), (u'ist', u'ist'))]
how can I transform the above to the below structure in the most pythonic way? With zip?
[((u'die', u'welt'), (u'die', u'WELT')),
((u'welt', u'ist'), (u'WELT', u'ist'))]
Upvotes: 4
Views: 59
Reputation: 90889
You can use zip()
function and list comprehension for this , as -
>>> lst = [((u'die', u'die'), (u'welt', u'WELT')),
... ((u'welt', u'WELT'), (u'ist', u'ist'))]
>>>
>>> [tuple(zip(*x)) for x in lst]
[(('die', 'welt'), ('die', 'WELT')), (('welt', 'ist'), ('WELT', 'ist'))]
Upvotes: 6