Entering edit mode
8.0 years ago
ashkan
▴
160
I have a dictionary like this small example:
raw = {'id1': ['KKKKKK', 'MMMMMMMMMMMMMMM'], 'id2': ['KKKKKM', 'KKKKKK']}
as you see the values are are list. I would like to replace the list with a number which is score. I score each character in the list based on their length. if the length is 6 to 11 they would get 1, from 12 to 17 would be 2 and 18 and longer would get 3. then I add up all scores per id and would have one score per id. here is small example:
score = {'id1': 3, 'id2': 2}
I wrote the following code but did not give what I want:
score = {}
for val in raw.values():
for i in val:
if len(i) >=6<12:
sc = 1
elif len(i) >=12<18:
sc = 2
else:
sc = 3
score[raw.keys()] = sc
Really, another question without following up on all previous threads?
bonus interval comparison or chained comparison operators
Good luck :)