Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69748 > unrolled thread
| Started by | Giuliano Bertoletti <gbe32241@libero.it> |
|---|---|
| First post | 2014-04-06 09:44 +0200 |
| Last post | 2014-04-09 05:51 -0400 |
| Articles | 4 on this page of 24 — 10 participants |
Back to article view | Back to comp.lang.python
Keeping track of things with dictionaries Giuliano Bertoletti <gbe32241@libero.it> - 2014-04-06 09:44 +0200
Re: Keeping track of things with dictionaries Peter Otten <__peter__@web.de> - 2014-04-06 10:23 +0200
Re: Keeping track of things with dictionaries Josh English <Joshua.R.English@gmail.com> - 2014-04-07 21:02 -0700
Re: Keeping track of things with dictionaries Chris Angelico <rosuav@gmail.com> - 2014-04-08 14:08 +1000
Re: Keeping track of things with dictionaries Josh English <Joshua.R.English@gmail.com> - 2014-04-07 23:22 -0700
Re: Keeping track of things with dictionaries "Frank Millman" <frank@chagford.com> - 2014-04-08 09:14 +0200
Re: Keeping track of things with dictionaries Steven D'Aprano <steve@pearwood.info> - 2014-04-08 07:47 +0000
Re: Keeping track of things with dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-08 01:53 -0600
Re: Keeping track of things with dictionaries Chris Angelico <rosuav@gmail.com> - 2014-04-08 18:00 +1000
Re: Keeping track of things with dictionaries Peter Otten <__peter__@web.de> - 2014-04-08 10:21 +0200
Re: Keeping track of things with dictionaries "Frank Millman" <frank@chagford.com> - 2014-04-08 10:26 +0200
Re: Keeping track of things with dictionaries "Frank Millman" <frank@chagford.com> - 2014-04-08 10:31 +0200
Re: Keeping track of things with dictionaries alex23 <wuwei23@gmail.com> - 2014-04-09 12:34 +1000
Re: Keeping track of things with dictionaries Chris Angelico <rosuav@gmail.com> - 2014-04-08 18:35 +1000
Re: Keeping track of things with dictionaries Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-09 12:43 +1200
Re: Keeping track of things with dictionaries Chris Angelico <rosuav@gmail.com> - 2014-04-09 12:33 +1000
Re: Keeping track of things with dictionaries alex23 <wuwei23@gmail.com> - 2014-04-09 12:45 +1000
Re: Keeping track of things with dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-08 21:19 -0600
Re: Keeping track of things with dictionaries Gene Heskett <gheskett@wdtv.com> - 2014-04-08 23:31 -0400
Re: Keeping track of things with dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-08 21:37 -0600
Re: Keeping track of things with dictionaries "Frank Millman" <frank@chagford.com> - 2014-04-08 11:28 +0200
Re: Keeping track of things with dictionaries Chris Angelico <rosuav@gmail.com> - 2014-04-08 19:34 +1000
Re: Keeping track of things with dictionaries "Frank Millman" <frank@chagford.com> - 2014-04-08 11:41 +0200
Re: Keeping track of things with dictionaries Gene Heskett <gheskett@wdtv.com> - 2014-04-09 05:51 -0400
Page 2 of 2 — ← Prev page 1 [2]
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Date | 2014-04-08 11:28 +0200 |
| Message-ID | <mailman.9005.1396949313.18130.python-list@python.org> |
| In reply to | #69830 |
"Chris Angelico" <rosuav@gmail.com> wrote in message
news:CAPTjJmoRxEhX02ZviHiLO+qi+dD+81smbGGYcPECpHb5E=p4=A@mail.gmail.com...
> On Tue, Apr 8, 2014 at 6:26 PM, Frank Millman <frank@chagford.com> wrote:
>>> words_by_length = {}
>>> for word in open("/usr/share/dict/words"):
>>> words_by_length.setdefault(len(word), []).append(word)
>>>
>>> This will, very conveniently, give you a list of all words of a
>>> particular length. (It's actually a little buggy but you get the
>>> idea.)
>>>
>>
>> Thanks, that is neat.
>>
>> I haven't spotted the bug yet! Can you give me a hint?
>
> Run those lines in interactive Python (and change the file name if
> you're not on Unix or if you don't have a dictionary at that path),
> and then look at what's in words_by_length[23] - in the dictionary I
> have here (Debian Wheezy, using an American English dictionary - it's
> a symlink to (ultimately) /usr/share/dict/american-english), there are
> five entries in that list. Count how many letters there are in them.
>
I don't have a large dictionary to test with, and a small list of words (ls
/etc > dict) did not throw up any problems.
Are you saying that
all([len(word) == 23 for word in words_by_length[23]]) # hope I got
that right
will not return True?
Frank
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-04-08 19:34 +1000 |
| Message-ID | <mailman.9006.1396949667.18130.python-list@python.org> |
| In reply to | #69830 |
On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman <frank@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 :) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Date | 2014-04-08 11:41 +0200 |
| Message-ID | <mailman.9007.1396950095.18130.python-list@python.org> |
| In reply to | #69830 |
"Chris Angelico" <rosuav@gmail.com> wrote in message news:CAPTjJmpPAqmb6No7UDdDAdqG_jv9yz0sN4d70KAsksbwWR3jdg@mail.gmail.com... > On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman <frank@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
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2014-04-09 05:51 -0400 |
| Message-ID | <mailman.9066.1397039127.18130.python-list@python.org> |
| In reply to | #69748 |
On Wednesday 09 April 2014 05:47:37 Ian Kelly did opine: > On Tue, Apr 8, 2014 at 9:31 PM, Gene Heskett <gheskett@wdtv.com> wrote: > >> 'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat. > > > > Source citation please? > > http://en.wikipedia.org/wiki/Pneumonoultramicroscopicsilicovolcanoconios > is > http://www.oxforddictionaries.com/definition/english/pneumonoultramicro > scopicsilicovolcanoconiosis > http://dictionary.reference.com/browse/Pneumonoultramicroscopicsilicovo > lcanoconiosis Damn, I should know better than call your bluff. Serves me right. :( Boil that down to its essence and it might be used for one of the miners lung problems (black or white lung) they eventually die from. I have a friend doing that as I type. And getting very close to the end of his rope. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page <http://geneslinuxbox.net:6309/gene> US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web