Skip to content

Instantly share code, notes, and snippets.

@daudahmad
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daudahmad/6c15d23f02dd76311792 to your computer and use it in GitHub Desktop.
Save daudahmad/6c15d23f02dd76311792 to your computer and use it in GitHub Desktop.
# a useful sorting function to have, concatenates key and value of a tuple and sorts based on that, useful if keys are not unique
def sortFunction(tuple):
""" Construct the sort string (does not perform actual sorting)
Args:
tuple: (rating, MovieName)
Returns:
sortString: the value to sort with, 'rating MovieName'
"""
key = unicode('%.3f' % tuple[0])
value = tuple[1]
return (key + ' ' + value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment