Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuple unpack in assignment

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)))
like image 380
user545424 Avatar asked Sep 05 '26 13:09

user545424


1 Answers

You can just concatenate the tuples directly:

>>> a = (5,)+(6, 7)     
>>> a
(5, 6, 7)
like image 128
Gareth Latty Avatar answered Sep 07 '26 03:09

Gareth Latty