On Wednesday 09 April 2014 05:47:37 Ian Kelly did opine:
On Tue, Apr 8, 2014 at 9:31 PM, Gene Heskett ghesk...@wdtv.com wrote:
'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat.
Source citation please?
On Monday, April 7, 2014 9:08:23 PM UTC-7, Chris Angelico wrote:
That depends on whether calling Brand() unnecessarily is a problem.
Using setdefault() is handy when you're working with a simple list or
something, but if calling Brand() is costly, or (worse) if it has side
effects that you
Chris Angelico ros...@gmail.com wrote in message
news:captjjmqfbt2xx+bdfnhz0gagordkhtpbzrr29duwn36girz...@mail.gmail.com...
On Tue, Apr 8, 2014 at 2:02 PM, Josh English joshua.r.engl...@gmail.com
wrote:
Would dict.setdefault() solve this problem? Is there any advantage to
defaultdict over
On Tue, 08 Apr 2014 09:14:39 +0200, Frank Millman wrote:
It appears that when you use 'setdefault', the default is always
evaluated, even if the key exists.
def get_value(val):
... print('getting value', val)
... return val*2
...
my_dict = {}
my_dict.setdefault('a',
On Tue, Apr 8, 2014 at 1:14 AM, Frank Millman fr...@chagford.com wrote:
Chris Angelico ros...@gmail.com wrote in message
news:captjjmqfbt2xx+bdfnhz0gagordkhtpbzrr29duwn36girz...@mail.gmail.com...
On Tue, Apr 8, 2014 at 2:02 PM, Josh English joshua.r.engl...@gmail.com
wrote:
Would
On Tue, Apr 8, 2014 at 5:14 PM, Frank Millman fr...@chagford.com wrote:
It appears that when you use 'setdefault', the default is always evaluated,
even if the key exists.
def get_value(val):
... print('getting value', val)
... return val*2
...
my_dict = {}
my_dict.setdefault('a',
Ian Kelly wrote:
One thing I will note as a disadvantage of defaultdict is that
sometimes you only want the default value behavior while you're
initially building the dict, and then you just want a normal dict with
KeyErrors from then on. defaultdict doesn't do that; once
constructed, it
Chris Angelico ros...@gmail.com wrote in message
news:captjjmpk-rqx0fp6_4vxyus2z34vc5fq_qntj+q9+kn8y5u...@mail.gmail.com...
On Tue, Apr 8, 2014 at 5:14 PM, Frank Millman fr...@chagford.com wrote:
It appears that when you use 'setdefault', the default is always
evaluated,
even if the key
Ian Kelly ian.g.ke...@gmail.com wrote in message
news:CALwzidmP5Bevbace9GyQrVXe-_2T=jtpq1yvapsaepvomqe...@mail.gmail.com...
On Tue, Apr 8, 2014 at 1:14 AM, Frank Millman fr...@chagford.com wrote:
It appears that when you use 'setdefault', the default is always
evaluated,
even if the key
On Tue, Apr 8, 2014 at 6:26 PM, Frank Millman fr...@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
Chris Angelico ros...@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 fr...@chagford.com wrote:
words_by_length = {}
for word in open(/usr/share/dict/words):
On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman fr...@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
Chris Angelico ros...@gmail.com wrote in message
news:captjjmppaqmb6no7udddadqg_jv9yz0sn4d70kasksbwwr3...@mail.gmail.com...
On Tue, Apr 8, 2014 at 7:28 PM, Frank Millman fr...@chagford.com wrote:
Are you saying that
all([len(word) == 23 for word in words_by_length[23]]) # hope I got
Chris Angelico wrote:
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.
Mine's bigger than yours! On MacOSX 10.6 I get 41 words.
(I think someone must have
On Wed, Apr 9, 2014 at 10:43 AM, Gregory Ewing
greg.ew...@canterbury.ac.nz wrote:
Chris Angelico wrote:
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.
On 8/04/2014 6:31 PM, Frank Millman wrote:
Here is an idea, inspired by Peter Otten's suggestion earlier in this
thread.
Instead of defaultdict, subclass dict and use __missing__() to supply the
default values.
When the dictionary is set up, delete __missing__ from the subclass!
Ugly, but it
On 9/04/2014 12:33 PM, Chris Angelico wrote:
Unfortunately I seem to be missing antidisestablishmentarianism,
because the longest words in my dict are only 24 characters,
excluding the '\n'. Should I ask for my money back?
I think you should. That's a fundamental flaw in the dictionary.
On Tue, Apr 8, 2014 at 8:45 PM, alex23 wuwe...@gmail.com wrote:
On 9/04/2014 12:33 PM, Chris Angelico wrote:
Unfortunately I seem to be missing antidisestablishmentarianism,
because the longest words in my dict are only 24 characters,
excluding the '\n'. Should I ask for my money back?
I
On Tuesday 08 April 2014 23:31:35 Ian Kelly did opine:
On Tue, Apr 8, 2014 at 8:45 PM, alex23 wuwe...@gmail.com wrote:
On 9/04/2014 12:33 PM, Chris Angelico wrote:
Unfortunately I seem to be missing antidisestablishmentarianism,
because the longest words in my dict are only 24 characters,
On Tue, Apr 8, 2014 at 9:31 PM, Gene Heskett ghesk...@wdtv.com wrote:
'Pneumonoultramicroscopicsilicovolcanoconiosis' has them all beat.
Source citation please?
http://en.wikipedia.org/wiki/Pneumonoultramicroscopicsilicovolcanoconiosis
On Sunday, April 6, 2014 12:44:13 AM UTC-7, Giuliano Bertoletti wrote:
obj = brands_seen.get(brandname)
if obj is None:
obj = Brand()
brands_seen[brandname] = obj
Would dict.setdefault() solve this problem? Is there any advantage to
defaultdict over setdefault()
Josh
--
On Tue, Apr 8, 2014 at 2:02 PM, Josh English joshua.r.engl...@gmail.com wrote:
On Sunday, April 6, 2014 12:44:13 AM UTC-7, Giuliano Bertoletti wrote:
obj = brands_seen.get(brandname)
if obj is None:
obj = Brand()
brands_seen[brandname] = obj
Would dict.setdefault() solve this
I frequently use this pattern to keep track of incoming data (for
example, to sum up sales of a specific brand):
=
# read a brand record from a db
...
# keep track of brands seen
obj = brands_seen.get(brandname)
if obj is None:
obj = Brand()
Giuliano Bertoletti wrote:
I frequently use this pattern to keep track of incoming data (for
example, to sum up sales of a specific brand):
=
# read a brand record from a db
...
# keep track of brands seen
obj = brands_seen.get(brandname)
if obj
24 matches
Mail list logo