> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Emad Nawfal > Sent: Wednesday, May 16, 2007 9:40 AM > To: Tutor@python.org > Subject: [Tutor] words and lengths > > 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
Instead of lengths = lengths[word, len(word)] I think it should be lengths[word] = len(word) # dictionary[key] = value Mike _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor