Created
January 27, 2016 02:37
-
-
Save datamafia/cb90339191a8fb3fb6b3 to your computer and use it in GitHub Desktop.
Looking for element in tuple inside list via len() as a boolean. Too cool to forget.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = [ | |
('a', 'b'), | |
('c', 'd') | |
] | |
if len([item[1] for item in t if item[0] == 'a']): | |
print 'yes' | |
else: | |
print 'no' | |
# yes | |
if len([item[1] for item in t if item[0] == 'e']): | |
print 'yes' | |
else: | |
print 'no' | |
# no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment