0
0
Apache Sparkdata~10 mins

Map, filter, and flatMap operations in Apache Spark - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to apply a map operation that doubles each number in the RDD.

Apache Spark
rdd2 = rdd.[1](lambda x: x * 2)
Drag options to blanks, or click blank then click option'
Amap
Bfilter
CflatMap
Dreduce
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of map, which would remove elements instead of transforming them.
Using reduce, which combines all elements into one value.
2fill in blank
medium

Complete the code to filter out all numbers less than 5 from the RDD.

Apache Spark
filtered_rdd = rdd.[1](lambda x: x >= 5)
Drag options to blanks, or click blank then click option'
Amap
Bfilter
CflatMap
Dreduce
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of filter, which would transform elements but not remove any.
Using flatMap, which expects a function returning a list or iterable.
3fill in blank
hard

Fix the error in the code to correctly flatten a list of words from sentences using flatMap.

Apache Spark
words = sentences.[1](lambda sentence: sentence.split(' '))
Drag options to blanks, or click blank then click option'
Afilter
Bmap
CflatMap
Dreduce
Attempts:
3 left
💡 Hint
Common Mistakes
Using map, which results in an RDD of lists instead of a flat list of words.
Using filter or reduce, which do not flatten lists.
4fill in blank
hard

Complete the code to create a dictionary of words and their lengths, but only for words longer than 3 characters.

Apache Spark
word_lengths = {word: len(word) for word in words if len(word) [1] 3}
Drag options to blanks, or click blank then click option'
A:
B>
C<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in dictionary comprehension.
Using '<' instead of '>' in the condition, which would select shorter words.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys, their original words as values, but only for words longer than 4 characters.

Apache Spark
result = [1]: [2] for word in words if len(word) [3] 4}
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
C>
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using length as a key or value instead of the word or its uppercase.
Using '<' instead of '>' in the condition.