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

from pyspark import SparkContext

sc = SparkContext()

list = [1, 2, 3, 4, 5, 6]

accumulator = sc.accumulator(0)


def f(item):
    accumulator.add(1)
    print("当前元素是：", item)


data = sc.parallelize(list, 4).foreach(lambda item: f(item))
print("循环次数：", accumulator.value)
