def reduce_by_max(rdd):
    """
    Helper function to find the max value in a list of values i.e. triplets. 
    """
max_val = rdd[0][2]
the_index = 0
for idx, val in enumerate(rdd):
    if val[2] > max_val:
        max_val = val[2]
the_index = idx
return rdd[the_index]
conf = SparkConf().setAppName('Collaborative Filter').set(
    'spark.executor.memory', '5g')
sc = SparkContext(conf=conf)
data_file = sc.textData('file:///some_file.txt')
data_file = data_file.map(lambda l: l.split()).map(lambda l: (l[0], l[1],
    float(l[2])))
grouped = data_file.groupBy(lambda r: r[0])
group_list = grouped.map(lambda x: list(x[1]))
max_list = group_list.map(reduce_by_max).collect()
pyspark: grouby and then get max value of each group