Complete the code to calculate the sum of all numbers in the RDD.
total_sum = numbers.[1](lambda x, y: x + y)collect returns all elements, not the sum.map transforms elements but does not aggregate.filter selects elements but does not combine.The reduce action combines all elements using a function, here summing all numbers.
Complete the code to find the maximum value in the RDD.
max_value = numbers.[1]()min returns the smallest element.reduce without a function will cause an error.count returns the number of elements, not the max.The max action returns the largest element in the RDD.
Fix the error in the code to correctly compute the sum using reduce.
total = numbers.reduce(lambda x, y: x [1] y)* will compute the product, not sum.- or division / will give wrong results.The reduce function needs to add elements to compute the sum, so use +.
Fill both blanks to create a dictionary of word counts using reduceByKey.
word_counts = words.[1](lambda a, b: a [2] b).collectAsMap()
map does not aggregate values.* will multiply counts incorrectly.reduceByKey groups values by key and combines them using the function. Here, + sums counts.
Fill all three blanks to create a dictionary of word lengths for words longer than 3 characters.
lengths = words.filter(lambda word: len(word) [3] 3).map(lambda word: (word[1](), [2])).collectAsMap()
== instead of > filters wrong words.This code creates keys as uppercase words and values as their lengths, filtering words longer than 3 characters.