I have a list of uncertain size:
l = [...]
And I want to unpack this list into a tuple that has other values, but the below fails:
As of python 3.5, you can now use your first approach:
>>> l = [1, 2, 3] >>> t = ("AA", "B", *l, "C") >>> t ('AA', 'B', 1, 2, 3, 'C')
You can use slices just as you'd expect:
>>> ("AA", "B", *l[:-1], "C") ('AA', 'B', 1, 2, 'C')
The related PEP, for reference: PEP448