Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-332

Type Token Ratio

Problem

The type-token ratio is the number of distinct types divided by the total number of tokens, a basic lexical diversity measure.

Given the token list, return the ratio, or 0.0 for an empty list.

Hint

Types over tokens.

Test cases

case 1
in: [["a","b","a"]]
expected: 0.6666666666666666
case 2
in: [["x","y","z"]]
expected: 1
case 3
in: [[]]
expected: 0
Starter codePython
def type_token_ratio(tokens):
    # Your code here
    pass

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