Adde21_30
Adde21_30

Reputation: 87

Comparing tuple contents with int in python

a = [(0, "Hello"), (1,"My"), (3, "Is"), (2, "Name"), (4, "Jacob")]

This is an example of a list, but when I try to this this it doesn't work:

if time < a[3]:
    print ("You did it!")

The problem is that I can't apparently compare a tuple with an int, but I only want to compare it to the first number in the tuple. How can I do this?

Upvotes: 0

Views: 389

Answers (1)

Moses Koledoye
Moses Koledoye

Reputation: 78554

This?

if time < a[3][0]:
#              ^
    print ("You did it!")

You can index the tuple the same way you did with the list.

Upvotes: 4

Related Questions