Предмет: Информатика,
автор: babule
Python!!!
Afișați cuvintele duplicat într-un șir. Dacă lipsesc, imprimați despre el
mesaj. Cuvintele sunt separate unele de altele printr-un spațiu.
(Вывести повторяющиеся слова в строке. Если они отсутствуют, то вывести об этом
сообщение. Слова разделены друг с другом пробелом.)
flash77779:
Выполнил задание
Ответы
Автор ответа:
0
import string
string = input("Enter a string: ").lower()
words = string.split()
duplicates = set()
uniques = set()
for word in words:
if word in uniques:
duplicates.add(word)
else:
uniques.add(word)
for duplicate in duplicates:
uniques.remove(duplicate)
if duplicates:
print("The duplicate words are:", duplicates)
else:
print("There are no duplicate words.")
print("The unique words are:", uniques)
Приложения:
Похожие вопросы
Предмет: Физика,
автор: sash4ka12345
Предмет: Қазақ тiлi,
автор: sariyushik
Предмет: Физика,
автор: mariacherevko2008
Предмет: Русский язык,
автор: Аноним