Python list of dictionaries search

后端 未结 21 2082
-上瘾入骨i
-上瘾入骨i 2020-11-22 09:41

Assume I have this:

[
{\"name\": \"Tom\", \"age\": 10},
{\"name\": \"Mark\", \"age\": 5},
{\"name\": \"Pam\", \"age\": 7}
]

and by searchin

21条回答
  •  -上瘾入骨i
    2020-11-22 10:14

    You have to go through all elements of the list. There is not a shortcut!

    Unless somewhere else you keep a dictionary of the names pointing to the items of the list, but then you have to take care of the consequences of popping an element from your list.

提交回复
热议问题