This is valid python to unpack a list with a single element:
list_with_one = [1]
[one] = list_with_one
print(one) # Prints 1
Is there some documentation for this anywhere?
Thanks again,
J.R.
This is valid python to unpack a list with a single element:
list_with_one = [1]
[one] = list_with_one
print(one) # Prints 1
Is there some documentation for this anywhere?
Thanks again,
J.R.
I suppose in the definition for assignment statment, although I’ll grant you that isn’t something most people read while learning the language.
Specifically, “an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets.”
That makes sense. Thanks!
Ahh, equivalent to this:
(one,) = list_with_one
Saves a comma I guess.
But wastes two brackets, compared to this:
one, = list_with_one