Skip to content

Instantly share code, notes, and snippets.

@NaPs
Created May 14, 2009 19:52
Show Gist options
  • Select an option

  • Save NaPs/111858 to your computer and use it in GitHub Desktop.

Select an option

Save NaPs/111858 to your computer and use it in GitHub Desktop.
>>> l
[(1, 1, 4), (3, 1, 11), (2, 1, 13), (6, 1, 17), (5, 1, 17), (4, 1, 18), (2, 2, 28), (1, 2, 29), (3, 2, 30), (4, 2, 31), (5, 2, 31), (6, 2, 33), (1, 3, 45), (3, 3, 51)]
>>> d = {}
>>> for x in l:
... if x[0] in d:
... if x[1] > d[x[0]][0]:
... d[x[0]] = x[1:]
... else:
... d[x[0]] = x[1:]
...
>>> d.items()
[(1, (3, 45)), (2, (2, 28)), (3, (3, 51)), (4, (2, 31)), (5, (2, 31)), (6, (2, 33))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment