Hello. In python, assignment operator can unpack list or tuple into variables, like this:
l = (1, 2)
a, b = l # here goes auto unpack
But i need to specify exactly same amount of names to the left as an items count in the list to the right. But sometimes i don't know a size of the list to the right, for example if i use split(). Example:
a, b = "length=25".split("=") # this will result in a="length" and b=25
But the following code will lead an error:
a, b = "DEFAULT_LENGTH".split("=") # error, list has only 1 item
is it possible to somehow unpack list in the example above so i get a = "DEFAULT_LENGTH" and b equals to 'None' or not set? Straightforward way looks kinda long:
a = b = None
if "=" in string :
a, b = string.split("=")
else :
a = string