All problems
Script Detection Heuristic
Problem
Return the dominant script of text by counting characters: 'latin' for a-z and A-Z, 'cyrillic' for U+0400-U+04FF, 'arabic' for U+0600-U+06FF, 'han' for U+4E00-U+9FFF, and 'digit' for decimal digits.
Return the category with the highest count, breaking ties by that same priority order, and 'other' when no scored character appears.
Hint
Check the code point ranges in ord(ch) and keep the first maximum.
Test cases
case 1
in: ["hello"]
expected: "latin"
case 2
in: ["Привет"]
expected: "cyrillic"
case 3
in: ["مرحبا"]
expected: "arabic"
case 4
in: ["你好"]
expected: "han"
case 5
in: ["12345"]
expected: "digit"
case 6
in: ["!!!"]
expected: "other"
Starter codePython
def detect_script(text):
# Your code here
pass6 test cases · run your code against them in the editor