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

Занятие 1. Entering and output of data

Difficulty level:

Task«Duplicate»

Improve a program that takes a line to the input and returns a list of its elements without recurring characters in a row. In this case, it is necessary to maintain the original relative order of the remaining elements.

Input format

One line of characters without spaces.

Output format

List (List) with filtered elements.

Example

Input

AAAABBCCDAABBB

Output

['a', 'b', 'c', 'd', 'a', 'b']

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
def unique_in_order(iterable):
    """
    Принимает последовательность и возвращает список элементов
    без одинаковых соседей, сохраняя исходный порядок.
    """
    if not iterable:
        return []

    result = [iterable[0]]
    for i in range(1, len(iterable)):
        if iterable[i] != iterable[i-1]:
            result.append(iterable[i])
    return result

# Основная часть программы для взаимодействия с пользователем
if __name__ == '__main__':
    # Получаем входную строку от пользователя
    input_data = input()
    
    # Вызываем функцию и получаем результат
    output_data = unique_in_order(input_data)
    
    # Печатаем результат в требуемом формате
    print(output_data)

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