I’m new to Python so my question may seem easy to some but then again I’m stuck on my own so I need your help! This is the code that i am having trouble with:
def identify_language(sequence, **common_words):
result = {}
for i in common_words:
result[i] = 0
for i in func_op(sequence.lower()):
for j in common_words:
if i in common_words[j]:
result[j] += 1
return sort(result[0][0])
...
dictionary = {'cro':list_cro, 'eng':list_cro}
language = identify_language('I had a little lamb. It was called Billy.', **dictionary)
I am trying to identify language based on samples which are in list_cro and list_eng (and hopefully others). I am getting KeyError: 0. Additionally, sort and func_op are working fine i tested then separately. What may be the problem?
Also, if i change order of arguments in function (putting list as a first argument and string as second) i am getting syntax error.
Thanks for listening!
At the end of the function,
resultshould look like this:{'cro': X, 'eng': Y}, where X and Y are numbers. I don’t know what your dictionaries are, so I can’t guess what the numbers are. Evaluatingresult['eng']will produce a number, as willresult['cro'], but there is no0key in this dictionary.Further, the second indexing operation will also give you issues.
result['eng'][0]will give you an error becauseresult['eng']is a number, and you can’t index into a number.What do you expect the output of this function to look like? Where is
sortdefined and what is it supposed to do?