try something like this:
>>> lis=(1,)[:2] #just one value,
>>> lis
(1,)
>>> lis=(1,2)[:2] #two values
>>> lis
(1, 2)
>>> lis=(1,2,3,4,5)[:2] #any number of values
>>> lis
(1, 2)
# used [:2] here, because you only expect a maximum of 2 values
# use [:] to collect any number of values
But the only problem with this approach is that you need to return a tuple
at every return
statement,
so return False
becomes return False,
using iter()
, this too expect that you always return a tuple or any iterable:
>>> ret=((1,))
>>> ret=iter((1,))
>>> a,b=ret.next(),list(ret)[:1] #used [:1] coz we need to store only 2 elements
>>> a,b
(1, [])
>>> ret=iter((1,2))
>>> a,b=ret.next(),list(ret)[:1]
>>> a,b
(1, [2])
>>> ret=iter((1,2,3,4))
>>> a,b=ret.next(),list(ret)[:1]
>>> a,b
(1, [2])