• 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
  • к

Занятие 3. FOR cycle

Difficulty level:

Task«Extra words»

your younger brother is approaching. You asked him what he wants as a gift. He was so delighted that he began to list everything in a row, repeating some names several times from excitement: “I want another machine and a doll and a robot and a robot and a robot again!”.

rn your task as an older and more technically unanimous relative & mdash; Help parents make a clear list of purchases. It is necessary to write a program that will process the enthusiastic speech of the child and remove all the repetitions from it, leaving only unique gift names. The order in the final list should be the same as in the child’s speech at the first mention of the gift.

rn

technical specifications:
Write a program that accepts one line of text, consisting of words separated by spaces. The program should derive a new line, which contains only unique words from the original line, preserved in the order of their first appearance. To decide, use only input/output, cycle & nbsp; for & nbsp; and conditional operator & nbsp; if

Input format

One line (string), consisting of words separated by spaces. Words are the names of gifts.

Output format

One line (string), which contains only unique words from the input line separated by a gap. The word order must correspond to their first appearance in the entrance line.

Example

Input

machine doll machine robot robot doll

Output

Machine Doll Robot

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
# Считываем всю строку, введенную пользователем
input_line = input()

# Разбиваем полученную строку на отдельные слова по пробелу, получаем список слов
words = input_line.split()

# Создаем пустой список, в который будем добавлять уникальные слова
unique_words = []

# Запускаем цикл, который перебирает каждое слово из списка words
for word in words:
    # Проверяем условие: если текущего слова еще нет в списке unique_words
    if word not in unique_words:
        # Если слово уникальное, добавляем его в конец списка unique_words
        unique_words.append(word)

# С помощью метода join соединяем слова из списка unique_words в одну строку,
# разделяя их пробелом, и выводим на экран
result_string = " ".join(unique_words)
print(result_string)

🎉 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, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!