Информатика, вопрос задал babule , 1 год назад

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: Выполнил задание

Ответы на вопрос

Ответил 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)

Приложения:
Новые вопросы