• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 6. Lists

Difficulty level:

Task«Alphabetical sorting»

Imagine that you help mom make a common purchase list. Mom recorded products in two different notebooks, and now you need to combine these lists into one in order not to buy anything superfluous and not forget anything. In addition, it is important for mom that the list is sorted by alphabet & ndash; It is more convenient to look for products in the store.
rn
& nbsp;

Input format

the name of the first product from the first notebook
the name of the second product from the first notebook
... (and so on, until the end signal is entered List)
stop & nbsp; (The end of the first list)
the name of the first product from the second notebook
The name of the second product from the second block
... (so on, until the end of the second list is introduced)
stop (signal About the end of the second list)

Output format

a united and sorted alphabetical list of purchases, each product from a new line

Example

Input

Apple
Banana
Milk
Stop
Bread
Eggs
Apple
Stop

Output

Banana
Bread
Milk
Apple
Eggs

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
# Создаем пустой список для первого списка продуктов
spisok1 = []
# Читаем продукты из первого списка до слова "стоп"
while True:
    produkt = input()
    if produkt == "стоп":
        break
    spisok1.append(produkt)

# Создаем пустой список для второго списка продуктов
spisok2 = []
# Читаем продукты из второго списка до слова "стоп"
while True:
    produkt = input()
    if produkt == "стоп":
        break
    spisok2.append(produkt)

# Объединяем два списка
obshiy_spisok = spisok1 + spisok2

# Удаляем дубликаты, преобразовав список во множество (set) и обратно в список
obshiy_spisok = list(set(obshiy_spisok))

# Сортируем список по алфавиту
obshiy_spisok.sort()

# Выводим отсортированный список
for produkt in obshiy_spisok:
    print(produkt)

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!