def language(s):
s = decode_utf8(s)<EOL>s = set(w.strip(PUNCTUATION) for w in s.replace("<STR_LIT:'>", "<STR_LIT>").split())<EOL>n = float(len(s) or <NUM_LIT:1>)<EOL>p = {}<EOL>for xx in LANGUAGES:<EOL><INDENT>lexicon = _module(xx).__dict__["<STR_LIT>"]<EOL>p[xx] = sum(<NUM_LIT:1> for w in s if w in lexicon) / n<EOL><DEDENT>return max(p.items(), key=lambda kv: (kv[<NUM_LIT:1>], int(kv[<NUM_LIT:0>] == "<STR_LIT>")))<EOL>
Returns a (language, confidence)-tuple for the given string.