[Tutor] words and lengths

Emad Nawfal emadnawfal at gmail.com
Wed May 16 17:40:16 CEST 2007


Hi All,
I'm beginning to learn Python for linguistic research using the Natural
Language Toolkit. I want to write a small piece of code to count lengths of
words and print them a long with the words. I've tried this but it does not
work. What's wrong with it, and how can I fix it?


phrase2 = ['colorless', 'green', 'ideas', 'sleep', 'furiously']
lengths = {}
for word in phrase2:
    lengths = lengths[word, len(word)]

print lengths
Thank you in anticipation

-- 
If everyone is thinking alike, then somebody isn't thinking." George S.
Patton
-------------------------------------------------------
Emad Soliman Nawfal
University of Arizona, Tucson
http://emadnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070516/990e3fdd/attachment.html 


More information about the Tutor mailing list