Let's say I have a list:
b = [ {'id':'e1'},{'id':'e100'},{'id':'e3'},{'id':'e2'} ]
I want to sort it by id numbers to look like that:
b = [{'id': 'e1'}, {'id': 'e2'}, {'id': 'e3'}, {'id': 'e100'}]
Let's say I have a list:
b = [ {'id':'e1'},{'id':'e100'},{'id':'e3'},{'id':'e2'} ]
I want to sort it by id numbers to look like that:
b = [{'id': 'e1'}, {'id': 'e2'}, {'id': 'e3'}, {'id': 'e100'}]
You could use sorted
. The following solution works, provided the value of 'id' starts with a single character followed by numbers.
sorted(b, key=lambda x: int(x['id'][1:]))