In [1]:
import sys

# Now we are ready to import Spark Modules
try:
    from pyspark import SparkContext
    from pyspark import SparkConf

except ImportError as e:
    print ("Error importing Spark Modules", e)
    sys.exit(1)

In [2]:
sc = SparkContext()
small_ints = sc.parallelize(range(10))

print ("add up 0 to 10 via reduce", small_ints.reduce(lambda x, y: x+ y))
print ("double 0 to 10 (using collect): ", small_ints.map(lambda x: 2*x).collect())
print ("double 0 to 10 (using take): ", small_ints.map(lambda x: 2*x).take(100))


('add up 0 to 10 via reduce', 45)
('double 0 to 10 (using collect): ', [0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
('double 0 to 10 (using take): ', [0, 2, 4, 6, 8, 10, 12, 14, 16, 18])

In [ ]: