This is and answer to one of the Vegaseat's recent projects for beginners.
I share my solution here because -as a begginer and do learn python as a hobby-
I need your feedback. So please tell me am I doing it the right way?
Thanks in advance for comments
from string import punctuation as punc def find_longest(text): words = list(set(word.strip(punc) for word in text.split())) length = len(sorted(words,key=len,reverse=1)) longest= [word for word in words if len(word)==length] return longest, length #=============== TEST ==============# text = """Python is probably one of the few programming languages which is both simple and powerful. This is good for both and beginners as well as experts, and more importantly, is fun to program with. This book aims to help you learn this wonderful language and show how to get things done quickly and painlessly - in effect 'The Perfect Anti-venom to your programming problems'.""" wordlist, length = find_longest(text) print "Longest Word's Length: %d" %length print "Longest Word(s): %s" %(str(wordlist))