0
0
Hadoopdata~10 mins

Reduce phase explained in Hadoop - Interactive Code Practice

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

Complete the code to define the reduce function that sums values for each key.

Hadoop
def reduce(key, values):
    result = 0
    for value in values:
        result += [1]
    return (key, result)
Drag options to blanks, or click blank then click option'
Akey
Bvalues
Cvalue
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'key' instead of 'value' inside the loop.
Adding 'values' instead of individual 'value'.
2fill in blank
medium

Complete the code to emit the final key-value pair from the reduce function.

Hadoop
def reduce(key, values):
    total = sum(values)
    [1](key, total)
Drag options to blanks, or click blank then click option'
Aprint
Boutput
Creturn
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of 'emit'.
Using 'return' which does not output to Hadoop.
3fill in blank
hard

Fix the error in the reduce function to correctly sum values.

Hadoop
def reduce(key, values):
    total = 0
    for val in values:
        total = total [1] val
    emit(key, total)
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which subtracts values.
Using '*' or '/' which multiply or divide.
4fill in blank
hard

Fill both blanks to create a dictionary of word counts using reduce logic.

Hadoop
word_counts = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Awords.count(word)
Blen(word)
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'len(word)' as count instead of 'words.count(word)'.
Using '<=' instead of '>' for filtering.
5fill in blank
hard

Fill all three blanks to create a reduce function that filters and sums values.

Hadoop
def reduce(key, values):
    filtered = [v for v in values if v [1] 10]
    total = sum(filtered)
    if total [2] 0:
        [3](key, total)
Drag options to blanks, or click blank then click option'
A>
B>=
Cemit
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for filtering.
Using 'print' instead of 'emit' to output.