Suppose I have a string of integers separated by commas of variable length. What is the best way to split the string and update variables with values if they exist?
Currently, I have the following.
a, b, c = 10, 10, 1 #default values
mylist = [int(x) for x in input.split(',')]
if len(mylist) == 2: a, b = mylist
else: a, b, c = mylist
Is there a more efficient way of doing this?
I think the reason this is ugly is that it’s non-Pythonic to treat local variables in aggregate; instance members would be more appropriate.