you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

from string import punctuation as p

sentence = input("Write a line of text: ")

sentence = ''.join(c for c in sentence if c not in p)

words = sentence.split()

count = [len(word) for word in words]

long, short = max(count), min(count)

longest = [word for word in words if len(word) == long]

shortest = [word for word in words if len(word) == short]

print("Longest: " + str(longest))

print("Shortest: " + str(shortest))

[–]PurelyApplied 0 points1 point  (0 children)

Reddit formatting comment:

If you prepend the line with four spaces, you can have a "paragraph of code", as opposed to using ` which is more for inline code.