Ich möchte gerne ein Programm schreiben, das das längste bzw. die längsten Wörter ausgibt.
Siehe dazu folgendes Snippet:
Code: Alles auswählen
## for each line in the file
for line in infile:
# split the line into a list of strings
line_list = line.split()
# print 'Line as List:', line_list
# for each word in the line
for word in line_list:
# check if the word is longer than the current longest word
if len(word) > max_word_length:
max_word = word
max_word_length = len(word)
for word in line_list: # neu: Alle längsten Wörter
if len(word) == max_word_length:
max_word_list.append(word)
Vielen Dank für die Korrektur.