Skip to content
Advertisement

Python unpack different elements in tuple into *args

var = ('3', [11, 13, 11, 11])

I want to convert it into something like this:

3 11 13 11 11

so that I can pass it into another function

foo(*args):
...

Advertisement

Answer

You could use iterable unpacking to do this.

You can unpack an iterable by prefixing it with * when passing it into a function.

foo(int(var[0]), *var[1]) would give you what you want.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement