Created
January 27, 2016 02:37
Looking for element in tuple inside list via len() as a boolean. Too cool to forget.
This file contains hidden or 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