words.txt:
Code: Alles auswählen
offer is secret click secret link secret sports link play sports today went play sports secret sports event sport is today sport costs money
Code: Alles auswählen
# coding: utf-8
# Python 3.2
from re import split
file = open("words.txt") # Enthält eine Liste von Wörtern, separiert durch \
# Leerzeichen. Keine Absätze enthalten.
content = file.read()
file.close()
words = split("\s", content)
for word in words:
print(word, words.count(word))
if words.count(word) > 1:
words.remove(word)
print(word, "entfernt.")
# Die Methode .remove entfernt nur ein einzelnes Wort.
print()
print(words)