In such an example:
"[{'id' : 18, 'name' : 'Rick'}, {'id' : 19, 'name' : 'Luke'}]"
I am working with a str
representation of a list
of dict
s. How can I iterate through the list to return a new list of all the "id's" in the dictionaries?
The desired result:
[18, 19]
EDIT:
I have tried already to cast the string into a list with ast.literal_eval(foolist)
and iterated through the items in the list. However, when I do this, it iterates through the characters in foolist
starting with "{"
then "'"
.