7

I have a tuple of tuples:

t = ((1, 'one'), (2, 'two'))

I need it in the following format:

((1, 2), ('one', 'two'))

How can I convert it? I can do something like:

digits     =  tuple ( digit for digit, word in t )
words      =  tuple ( word for digit, word in t )
rearranged =  tuple ( digits, words )

But that seems not elegant, I suppose there's a more straightforward solution.

Smandoli
  • 6,919
  • 3
  • 49
  • 83
lizarisk
  • 7,562
  • 10
  • 46
  • 70

1 Answers1

14

Use the following:

tuple(zip(*t))
Elmar Peise
  • 14,014
  • 3
  • 21
  • 40