How may I access to a tuple initialized within a if/else statement without using tuple() and list() functions?
I have this code:
if x > y:
foo = (a, b)
elif y > x:
foo = (b, a)
(tmp1, tmp2) = foo
but python returns: UnboundLocalError: local variable 'foo' referenced before assignment.
In other programming languages you can initialize the variable outside the statement, but what about this case?
Important: I need to work with a tuple, not a list.
Update: I don't need the case x == y, so I've changed my code adding a further condition:
foo = None
if x > y:
foo = (a, b)
elif y > x:
foo = (b, a)
if foo != None:
(tmp1, tmp2) = foo
Update2: Or, similarly:
if x > y:
foo = (a, b)
elif y > x:
foo = (b, a)
else:
foo = ()
if len(foo) > 0:
(tmp1, tmp2) = foo