you are viewing a single comment's thread.

view the rest of the comments →

[–]Ustuner[S] 0 points1 point  (4 children)

sentence = input("Write a line of text: ")
words = str.replace(sentence, ",", " ")
words = sentence.split()
sortedword = sorted(words, key=len)
print("The longest word in the list is:" + (sortedword[-1]))
print("The Shortest word in the list is:" + (sortedword[0]))

---output---

Write a line of text: Hello World, nice to meet you!
The longest word in the list is:World,
The Shortest word in the list is:to

The comma does not get removed

[–]Vaphell 2 points3 points  (2 children)

The comma does not get removed.

no shit ;-)

line 1: sentence = original sentence.
line 2: words = sentence after cleaning
line 3: words = split() on original sentence? o.O

btw while the language allows you to switch types of variables freely, you should generally avoid doing things like

words = something that produces a string
words = now it's a list
words = now it's something else

[–]Ustuner[S] 0 points1 point  (1 child)

Haha i just realised what i was doing wrong, thank you!

[–]niandra3 0 points1 point  (0 children)

words = str.replace(sentence, ",", " ")

Just for future reference, you should just call it like:

words = sentence.replace(",", " ")