Skip to content

Instantly share code, notes, and snippets.

@datamafia
Created January 27, 2016 02:37
Show Gist options
  • Save datamafia/cb90339191a8fb3fb6b3 to your computer and use it in GitHub Desktop.
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.
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