Hello people. I would like to ask experienced programmers (and Zed himself) if my programmer style is at least average. There are some flaws like one list for one type of words. Sorry for my grammar, english is not my first language. I look forward to your tips.
This code is written to pass test. All is written in english so I think it’s readable. 42 lines long
Source code:
Edit: Code is updated. It is almost completely rewriten.
Edit2: Another update. Hope it’s better than best @zedshaw
lexicon = {'north':'direction',
'NORTH':'direction',
'North':'direction',
'south':'direction',
'South':'direction',
'SOUTH':'direction',
'East':'direction',
'EAST':'direction',
'east':'direction',
'west':'direction',
'West':'direction',
'WEST':'direction',
'go':'verb',
'kill':'verb',
'eat':'verb',
'the':'stop',
'in':'stop',
'of':'stop',
'bear':'noun',
'princess':'noun'
}
def scan(words):
breaked_words = words.split()
result = []
for key in breaked_words:
item = lexicon.get(key)
try:
if item:
prepared = item, key
result.append(prepared)
else:
prepared = 'number', int(key)
result.append(prepared)
except ValueError:
prepared = 'error', key
result.append(prepared)
return result