Keeping track of things with dictionaries
Frank Millman
frank at chagford.com
Tue Apr 8 05:41:20 EDT 2014
More information about the Python-list mailing list
Tue Apr 8 05:41:20 EDT 2014
- Previous message (by thread): Keeping track of things with dictionaries
- Next message (by thread): Keeping track of things with dictionaries
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Chris Angelico" <rosuav at gmail.com> wrote in message news:CAPTjJmpPAqmb6No7UDdDAdqG_jv9yz0sN4d70KAsksbwWR3jdg at mail.gmail.com... > On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman <frank at chagford.com> wrote: >> Are you saying that >> >> all([len(word) == 23 for word in words_by_length[23]]) # hope I got >> that right >> >> will not return True? > > That'll return true. What it won't show, though, is the length of the > word as you would understand it in the English language. You see, when > you iterate over a file, you get strings that include a newline at the > end, and that'll be included in the length :) So with a dictionary of > English words, you'll see that "cat\n" is a four-letter word, and > "python\n" is a seven-letter word. It's a subtle point, but an > important one when you start looking at lengths of things that are > suddenly off by one. > > Obviously the solution is to strip them, but I didn't want to pollute > the example with that (nor a 'with' block). I didn't think it > particularly important, and just acknowledged the bug in what I > thought was a throw-away line :) > Got it - thanks Frank
- Previous message (by thread): Keeping track of things with dictionaries
- Next message (by thread): Keeping track of things with dictionaries
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list