Question

I would like to unpack a tuple in a python statement like so:

a = 5, *(6,7)

but this raises a SyntaxError. What is the cleanest way to achieve something like this?

The best I've come up with so far is:

a = tuple([5]+list((6,7)))
Was it helpful?

Solution

You can just concatenate the tuples directly:

>>> a = (5,)+(6, 7)     
>>> a
(5, 6, 7)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top