I have a list of dictionaries that I want to iterate over, but I only want to iterate up until a specific index rather that the entirety of the list.
My code:
new_hero_list = []
for hero in hero_data:
dict = {key: value for key, value in hero.items() if key in keys}
# some stuff ...
new_hero_list.append(dict)
The list hero_data
contains 100+ dictionaries, but in most cases I only want to iterate over the first nth
indexes, such as 3. How could I achieve this?