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)
Приложения:
Вас заинтересует
1 год назад
1 год назад
3 года назад
3 года назад
8 лет назад