Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-012

Lemmatization Map Lookup

Problem

Map each token to its lemma using the provided dictionary.

Fall back to the token itself when it is not a key in the map. Return an empty list for empty input.

Hint

dict.get(key, default) provides the fallback in one call.

Test cases

case 1
in: [["running","cats","was","better"],{"running":"run","was":"be","better":"good"}]
expected: ["run","cats","be","good"]
case 2
in: [["dogs","dogs"],{"dogs":"dog"}]
expected: ["dog","dog"]
case 3
in: [[],{"x":"y"}]
expected: []
case 4
in: [["a","b"],{}]
expected: ["a","b"]
Starter codePython
def lemmatize_lookup(tokens, lemma_map):
    # Your code here
    pass

4 test cases · run your code against them in the editor