Its easy to sort a dict to list by values, but I need to order keys by kind of boosting specific values in correlation to others.
An example:
x = [('key1', {'s': 'foo', 'w': 30}), ('key2', {'s': 'bar', 'w': 26}),
('key3', {'s': 'foo', 'w': 23}), ('key4', {'s': 'bar', 'w': 13})]
result: ['key2', 'key1', 'key3', 'key4']
The stuff is ordered by 'w', but for 's' we prefer 'bar' over 'foo' if 'w' hits some treshold. Is this somehow implemented in python, are there any rules to do this or do you know a python library to handle it?
Its not about learning the features, its about ordering the way I specify - boost or restrict - the values.
No answer helped so far, but solution for me is:
Every key get a score at the beginning of 1.0 and then for every feature/value I multiply it with sth. and at the end I do a normal ordering.
key1['score'] is 1.0
# feature 1
if key['s'] == foo:
score = score * 0.1
else:
score = score * 0.6
# feature 2
... and so on
order keys by score, done.
Thx, for your questions, thoughts and comments.