I have a function that returns a list. The length of this list is unknown to the caller.
def get_array():
ret = [1, 2]
return ret
var1, var2 = get_array()
This sets var1 = 1 and var2 = 2. This works fine with all lists except when the length is less than 2. For example, if the list has length of 1:
def get_array():
ret = [1]
return ret
var1 = get_array()
This sets var1 to [1], but I want var1 to be 1. Is there a cleaner way to unpack this array without having to check its length?
var1, = get_array()