daud-a
8/25/2015 - 12:29 PM

Useful Python code in Spark.py

# 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)