I have only recently begun programming in Python (with previous Ruby experience). I am trying to set up an if condition with two conditions:
if not previous[1] and previous[0][0] == 5:
print "hello world"
However, I keep getting this error:
<type 'exceptions.IndexError'>: tuple index out of range
Print previous returns: ((5, 1, 9, 23),)
What am I doing wrong?
I am looking for something similar to they Ruby Syntax: unless previous[1]
((5, 1, 9, 23),), then this is a length-1 tuple. It’s only element–with index 0–is the tuple(5, 1, 9, 23). It doesn’t have a second element to have the index1, sothat_tuple[1]raisesIndexError.What did you hope
previous[1]would give you?