Derive expressions (a) through (f) using only the information given in the table. code example
Example 1: Aggregate the elements of each partition, and then the results for all the partitions
#Aggregate the elements of each partition, and then the results for all the partitions
seqOp = (lambda x, y: (x[0] + y, x[1] + 1))
combOp = (lambda x, y: (x[0] + y[0], x[1], y[1]))
sc.parallelize([1, 2, 3, 4]).aggregate((0, 0), seqOp, combOp)
# (10, 4)
sc.parallelize([]).aggregate((0, 0), seqOp, combOp)
# (0, 0)
Example 2: Write a function called square_odd that has one parameter. Your function must calculate the square of each odd number in a list. Return a Python 3 list containing the squared values Challenge yourself: Solve this problem with a list comprehension!
nums = [square_odds**2 for square_odds in nums if square_odds%2 != 0]