Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'important,': 0.07; 'suddenly': 0.07; 'iterate': 0.09; 'newline': 0.09; 'subtle': 0.09; 'cc:addr:python-list': 0.11; 'bug': 0.12; 'language.': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lengths': 0.16; 'subject:dictionaries': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'file,': 0.19; 'example': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'see,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'included': 0.31; 'end,': 0.31; 'strip': 0.31; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'words,': 0.36; "didn't": 0.36; 'pm,': 0.38; 'though,': 0.39; 'hope': 0.61; 'length': 0.61; "you'll": 0.62; 'frank': 0.68; "'with'": 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=JUmScG5Iia9Oc8BZGMhTYtd5djnytCJ0joCmlxUrq+I=; b=ayCthKWC6qNwEfULjt8HRtFK/bL2jcLDZr29pWk7M2h4cmMKVi+jWNCs0j3hbMQ3ZS RxsayGmkoPw74kBZoDXfwlfl0x/DqZQxONVF5ZJKSOPetsWKIqxc0TDNGx1c5s/Z9Nni stH1cXGnqcy03Q27ofijLdMkreEcMKoGSuXOs57XJEfQy2EIsYlrPpftO1vfWArBx+Vj z2tigl7e+9NvGTnTKxC6q1daHx4a3bHKq4WEAnXhHT2Ds71waetR4Rc/GqDAA3UfoqaS beE6TbbyTodRIgcA1rJlOjrdeVch3vx++djOu7umPVa64Gtp+EOE4LCVPkNnCgG492Is C9+g== MIME-Version: 1.0 X-Received: by 10.68.201.10 with SMTP id jw10mr3202046pbc.25.1396949664943; Tue, 08 Apr 2014 02:34:24 -0700 (PDT) In-Reply-To: References: <534105ce$0$1365$4fafbaef@reader1.news.tin.it> <21ef5159-ad95-4d43-a2d6-7ecda941d978@googlegroups.com> Date: Tue, 8 Apr 2014 19:34:24 +1000 Subject: Re: Keeping track of things with dictionaries From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396949667 news.xs4all.nl 2833 [2001:888:2000:d::a6]:57448 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69849 On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman 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 :) ChrisA