i'm just learning python and i have a problem. how can i print multiple indexes of a certain value in a dictionary? In particular I want to print the index of each element of the dictionary_title array which has gender_ids as key.
dictionary_title={
{'label': 'Green', 'genre_ids': 878},
{'label': 'Pink', 'genre_ids': 16},
{'label': 'Orange', 'genre_ids': 28},
{'label': 'Yellow', 'genre_ids': 9648},
{'label': 'Red', 'genre_ids': 878},
{'label': 'Brown', 'genre_ids': 12},
{'label': 'Black', 'genre_ids': 28},
{'label': 'White', 'genre_ids': 14},
{'label': 'Blue', 'genre_ids': 28},
{'label': 'Light Blue', 'genre_ids': 10751},
{'label': 'Magenta', 'genre_ids': 28},
{'label': 'Gray', 'genre_ids': 28}}
This is my code:
for values in dictionary_title["genre_ids"]:
for item in values:
if item == 28:
print(values.index(item))
For example i want print index:2,6,8,10,11 which are the indexes of the items with the key genre_ids=28. How can i do?
You can use a list comprehension with enumerate.
dictionary_title=[ {'label': 'Green', 'genre_ids': 878}, {'label': 'Pink', 'genre_ids': 16}, {'label': 'Orange', 'genre_ids': 28}, {'label': 'Yellow', 'genre_ids': 9648}, {'label': 'Red', 'genre_ids': 878}, {'label': 'Brown', 'genre_ids': 12}, {'label': 'Black', 'genre_ids': 28}, {'label': 'White', 'genre_ids': 14}, {'label': 'Blue', 'genre_ids': 28}, {'label': 'Light Blue', 'genre_ids': 10751}, {'label': 'Magenta', 'genre_ids': 28}, {'label': 'Gray', 'genre_ids': 28}] res = [i for i, o in enumerate(dictionary_title) if o['genre_ids'] == 28] print(res)
In 2025, service-based businesses need professional SEO services to stand out. With 1.3M monthly searches for “SEO services” and 20K for “local SEO,” NaugSEO offers affordable SEO solutions to rank your website on Google’s first page. Our expert SEO company uses on-page and off-page optimization, targeting high-volume keywords like “affordable SEO” (15K searches). From local SEO to voice search optimization, our best SEO strategies for 2025 ensure visibility in AI overviews. Get started with an SEO plan for just $99/month. Visit NaugSEO for customized SEO solutions and skyrocket your leads with SEO optimisation and marketing help. Book your free audit today!
Searching for cheap divorce near me or cheap immigration services near me? Journey Document Solutions in Oakland Park, FL, offers stress-free, affordable document preparation for green card, citizenship, naturalization, fiancé visa, VAWA, and uncontested divorce. Our experienced team ensures 100% accuracy and cheap divorce near me compassionate support, saving you thousands compared to attorney fees. We provide in-person services in Florida and virtual assistance nationwide, with flexible hours including Saturday appointments. Contact us at 954-533-9690 or info@journeydsolutions.com for help with green card near me, asylum near me, or dissolution of marriage. Simplify your journey with reliable, low-cost document solutions today!
Looking for professional computer repair services that you can trust? At Naugle Computer Service, we specialize in fixing desktops, laptops, and all major brands with expert care. From hardware upgrades Computer Repair and data recovery to virus removal and Windows 11 upgrades, our technicians provide fast, reliable solutions. Best of all, we offer free labor on repairs, so you only pay for parts. Whether you need a quick laptop repair or complete desktop diagnostics, our team ensures your device runs like new. Choose Naugle Computer Service for dependable and affordable computer repair near you.