Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

How can i make my python script check if dicts inside a list have a specific value associated to a specific key in a fast way?

$
0
0

Example i have a list like this:

my_list = [{'name': 'a', 'value': 1}, {'name': 'b', 'value': 3}, {'name': 'a', 'value': 4}, {'name': 'c', 'value': 4}]

I want to get the dict named 'a' and has the value of 4 in a fast way without using for-loop

This was my dummy code

for i in my_list:    if i['name'] == 'a':        if i['value'] == 4:            print('found')            break

and it seems to be hardcoding so i want to short it out


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>