Domanda

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)))
È stato utile?

Soluzione

You can just concatenate the tuples directly:

>>> a = (5,)+(6, 7)     
>>> a
(5, 6, 7)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top