D.Super Fireball
D.Super Fireball

Reputation: 45

Is there anyway I could remove the parentheses from a tuple in a list and the commas?

Let's say I had some code like this:

import itertools

listone = list(itertools.permutations([1,2],2))

The output would be :

[(1,2),(2,1)]

Is there anything I could add to my code to make the output:

[12,21]

Upvotes: 0

Views: 59

Answers (1)

Dan D.
Dan D.

Reputation: 74645

Sure, assuming that the each of the numbers is a solution to 0 <= n < 10 and that the first number in the tuple is a solution to n != 0 then the following is reversible:

>>> [int(''.join(str(e) for e in t)) for t in [(1,2),(2,1)]]
[12, 21]
>>> [tuple(int(e) for e in str(t)) for t in [12, 21]]
[(1, 2), (2, 1)]

But this is most likely not that useful

Upvotes: 2

Related Questions