brennerm / PyTricks

Collection of less popular features and tricks for the Python programming language
MIT License
3.07k stars 503 forks source link

New Trick: judge an object in a list of tuple #31

Closed axiaoxin closed 9 years ago

axiaoxin commented 9 years ago
#! /usr/bin/env python
'''there is a list of tuple, and if you want to judge an object in this list by an elegant way, then...'''

from more_itertools import flatten     # pip install more_itertools

types = [('E', 'I'), ('S', 'N'), ('T', 'F'), ('J', 'P')]

if __name__ == '__main__':    
    assert 'E' in flatten(types)
    assert 'X' in flatten(types)