0

I am working on a list containing of tuples like

list = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)]

and transpose it

transpose = zip(*list)

so i get

transpose = [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]

after that i am removing some of the tuples of the transponed list for example the second tuple (2, 6, 10). How can i undo the transpose now? I want to achieve a list like:

[(1, 3, 4), (5, 7, 8), (9, 11, 12)]
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Pavel
  • 11
  • 3
  • 3
    You do realise that transposing is reversed by transposing? – MisterMiyagi Sep 16 '21 at 17:09
  • 1
    Although I don't think this is your issue, don't overwrite python builtins/keywords such as `list` unless you really know what you're doing as now you won't be able to use the keyword `list` as originally intended by the language. – Jab Sep 16 '21 at 17:15
  • It's in the `zip` function's [documentation](https://docs.python.org/3/library/functions.html#zip). Note the last example with the `zip(*zip(x, y))`. – martineau Sep 16 '21 at 17:17
  • Beside the point, but you might be accidentally using the wrong version of Python since you're saying `zip` gives you a list, but in Python 3, it should give you an iterator. I already removed the [tag:python-3.8] tag since this isn't specific to 3.8, and then I was going to add back the [tag:python-3] tag until I noticed the problem. – wjandrea Sep 16 '21 at 17:30
  • @Pavel what about keeping track the position of the removed tuple and add it again using a slice around that index? ... or you can avoid to remove... or make a copy of the original one... don't understand what is about the `zip`stuff and more generally what are you doing – cards Sep 16 '21 at 17:36

0 Answers0