Answer the question
In order to leave comments, you need to log in
Dictionary lists Oddity or bug?
The task was like this ...
you need to sort the list of dictionaries and
leave only dictionaries with the country Russia there
x = "Россия"
geo_logs = [
{'visit1': ['Москва', 'Россия']},
{'visit2': ['Дели', 'Индия']},
{'visit3': ['Владимир', 'Россия']},
{'visit4': ['Лиссабон', 'Португалия']},
{'visit5': ['Париж', 'Франция']},
{'visit6': ['Лиссабон', 'Португалия']},
{'visit7': ['Тула', 'Россия']},
{'visit8': ['Тула', 'Россия']},
{'visit9': ['Курск', 'Россия']},
{'visit10': ['Архангельск', 'Россия']},
{'visit11': ['Минск', 'Беларусь']},
{'visit12': ['Париж', 'Франция']}
]
for element in geo_logs:
for visit, country in element.items():
if country[1] != x:
geo_logs.remove(element)
print(geo_logs)
Answer the question
In order to leave comments, you need to log in
You can't iterate over a list and remove elements at the same time. Iterate over the copy and remove from the original array.
for element in geo_logs[:]:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question