Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python2
- def variant_1(tups, front):
- for tup in tups:
- if tup[0] == front:
- print tup
- def variant_2(tups, front):
- lookup = {tup[0]: tup for tup in tups}
- try:
- print lookup[front]
- except KeyError:
- pass
- def variant_3(tups, front):
- filtered = [tup for tup in tups if tup[0] == front]
- print filtered
- def main():
- tups = [((1, 2), 'word1', 1), ((2, 2), 'word2', 2), ((3, 2), 'word3', 3)]
- front = (3, 2)
- for variant in (variant_1, variant_2, variant_3):
- variant(tups, front)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement