Answer the question
In order to leave comments, you need to log in
How to sort the list with cities?
Here is the list:
['Краснодар', 'Сочи', 'Нижний', 'Новгород', 'Новосибирск', 'Красноярск', 'Уфа', 'Санкт-Петербург', 'Владимир', 'Москва']
Answer the question
In order to leave comments, you need to log in
As an option:
first_cities = ['Москва', 'Санкт-Петербург']
first_plus_sorted_cities = first_cities + sorted(city for city in all_cities if city not in first_cities)
A strange question - you sort your list, then transfer the necessary cities to its beginning. Moreover, the operation is done once and the list is short.
If the list is very long - first delete the necessary cities, sort the rest, then add the discarded cities to its beginning.
What is the problem?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question