[Tutor] words and lengths

Bob Gailer bgailer at alum.rpi.edu
Wed May 16 23:03:49 CEST 2007


Please use plain text. Color hurts my eyes, does NOT help me read your 
program.

Emad Nawfal wrote:
> 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
> --------------------------------------------------------
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
510-978-4454



More information about the Tutor mailing list