내가 당면한 문제와 해결방안
python find element in dictionary list using key value
한만큼
2019. 11. 21. 13:27
https://stackoverflow.com/a/8653568/10194999
Python list of dictionaries search
Assume I have this: [ {"name": "Tom", "age": 10}, {"name": "Mark", "age": 5}, {"name": "Pam", "age": 7} ] and by searching "Pam" as name, I want to retrieve the related dictionary: {name: "Pam", ...
stackoverflow.com
dicts = [
{ "name": "Tom", "age": 10 },
{ "name": "Mark", "age": 5 },
{ "name": "Pam", "age": 7 },
{ "name": "Dick", "age": 12 }
]
next((item for item in dicts if item["name"] == "Pam"), None)
을 쓰라구 한다. 이걸 좀 알아둬야겠어 매번 검색하기도 피곤해 ㅠㅠ
참고