# In Python 3
# https://pastebin.com/fPSmmE5w
longest = [""]
shortest = None
with open("words.txt") as words:
for line in words.readlines():
for word in line.split():
if len(word) > len(longest[0]):
longest = [word]
elif len(word) == len(longest[0]):
longest.append(word)
elif shortest is None or len(word) < len(shortest[0]):
shortest = [word]
elif len(word) == len(shortest[0]):
shortest.append(word)
def format_printable(words):
return ["{}: {}".format(len(word), word) for word in words]
print(
"Longest:\n",
"\n".join(format_printable(longest)),
"\nShortest:\n",
"\n".join(format_printable(shortest)),
)