#!/usr/bin/python
# -*- coding: UTF-8 -*-

from pyspark import SparkContext

sc = SparkContext()

rdd = sc.parallelize([("黑虎虾", 139), ("黑虎虾", 100), ("扇贝", 16.9), ("扇贝", 10.2),
                      ("海参", 59.9), ("鲈鱼", 35.9), ("罗非鱼", 29.9)])

def to_list(a):
    return [a]

def append(a, b):
    a.append(b)
    return a

def extend(a, b):
    a.extend(b)
    return a

result = rdd.combineByKey(to_list, append, extend).collect()

def f(item):
    print("当前元素是：", item)

[f(item) for item in result]
