Отсортирована итерация
basket = ['pear', 'banana', 'orange', 'pear', 'apple']
# use sorted to return a new sorted list before iterating
for fruit in sorted(basket):
print(fruit)
# =>
# apple
# banana
# orange
# pear
# pear
Cheerful Cow