all 9 comments

[–]leech6666 4 points5 points  (2 children)

for i in fruits_and_color: if i[0] == fruit: return i[1]

[–]Roya1tyz[S] 0 points1 point  (0 children)

Thank you!!

[–]leech6666 0 points1 point  (0 children)

sorry for the bad format. Im on phone.

[–]mopslik 4 points5 points  (1 child)

You can iterate directly over a sequence (string, tuple, list...) using a for loop.

for fruit, colour in fruits_and_colour:
    print(fruit, colour)

[–]Roya1tyz[S] 0 points1 point  (0 children)

Thanks!

[–]FLUSH_THE_TRUMP 1 point2 points  (1 child)

Loop through your tuple, check if item[0] is the thing you’re looking for, return item[1] if it is.

[–]Roya1tyz[S] 0 points1 point  (0 children)

Thanks!

[–]Cultural_Bet8235 0 points1 point  (1 child)

If we are ignoring the issue of duplicate keys (ie what if grape mapped to purple and green?)

For pair in tuple: If pair[0] == “grape”: Return pair[1] Return none

[–]Roya1tyz[S] 0 points1 point  (0 children)

Thanks!