RE: A little morning puzzle

2012-09-27 Thread Prasad, Ramit
Dwight Hutto wrote: > > Ergo: 'enumerate()' is the correct suggestion over manually > > maintaining your own index, despite it ostensibly being "more" code > > due to its implementation. > > But, therefore, that doesn't mean that the coder can just USE a > function, and not be able to design it th

Re: A little morning puzzle

2012-09-24 Thread Dwight Hutto
The posted code produces neither a set nor any keys; > it prints out the same predetermined non-key value multiple times. This shows multiple dicts, with the same keys, and shows different values, and some with the same, and that is, in my opinion what the OP asked for: a = {} a['dict'] = 1 b =

Re: A little morning puzzle

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 4:07 PM, Dwight Hutto wrote: > They stated: > > I have a list of dictionaries. They all have the same keys. I want to find > the > set of keys where all the dictionaries have the same values. Suggestions? > > No, to me it meant to find similar values in several dicts wi

Re: A little morning puzzle

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 5:18 PM, Ethan Furman wrote: > Ian Kelly wrote: >> >> On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto >> wrote: >>> >>> Why don't you all look at the code(python and C), and tell me how much >>> code it took to write the functions the other's examples made use of >>> to comp

Re: A little morning puzzle

2012-09-24 Thread Ethan Furman
Ian Kelly wrote: On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto wrote: Why don't you all look at the code(python and C), and tell me how much code it took to write the functions the other's examples made use of to complete the task. Just because you can use a function, and make it look easier,

Re: A little morning puzzle

2012-09-24 Thread Dwight Hutto
> Ergo: 'enumerate()' is the correct suggestion over manually > maintaining your own index, despite it ostensibly being "more" code > due to its implementation. But, therefore, that doesn't mean that the coder can just USE a function, and not be able to design it themselves. So 'correct suggestion

Re: A little morning puzzle

2012-09-23 Thread Ian Kelly
On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto wrote: > Why don't you all look at the code(python and C), and tell me how much > code it took to write the functions the other's examples made use of > to complete the task. > > Just because you can use a function, and make it look easier, doesn't > m

Re: A little morning puzzle

2012-09-23 Thread alex23
On Sep 23, 1:44 pm, Dwight Hutto wrote: > Just because you can use a function, and make it look easier, doesn't > mean the function you used had less code than mine, so if you look at > the whole of what you used to make it simpler, mine was on point. Word of advice: when we use "simpler" around

Re: A little morning puzzle

2012-09-22 Thread Dwight Hutto
On Thu, Sep 20, 2012 at 12:28 PM, Tobiah wrote: > >>> Here is my solution: > > >>> ** Incredibly convoluted and maximally less concise solution >>> than other offerings. ** > > >>> Might be better ones though. >> >> >> Unlikely. > > > Zing! > Why don't you all look at the code(python and C), and

Re: A little morning puzzle

2012-09-20 Thread Tobiah
Here is my solution: ** Incredibly convoluted and maximally less concise solution than other offerings. ** Might be better ones though. Unlikely. Zing! -- http://mail.python.org/mailman/listinfo/python-list

Re: A little morning puzzle

2012-09-19 Thread Paul Rubin
Neal Becker writes: > I have a list of dictionaries. They all have the same keys. I want to find > the > set of keys where all the dictionaries have the same values. Suggestions? Untested, and uses a few more comparisons than necessary: # ds = [dict1, dict2 ... ] d0 = ds[0] ks = set(k for

Re: A little morning puzzle

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 6:13 AM, Antoon Pardon wrote: > On 19-09-12 13:17, Neal Becker wrote: >> I have a list of dictionaries. They all have the same keys. I want to find >> the >> set of keys where all the dictionaries have the same values. Suggestions? > common_items = reduce(opereator.__an

Re: A little morning puzzle

2012-09-19 Thread Dwight Hutto
On Wed, Sep 19, 2012 at 8:01 AM, Dwight Hutto wrote: >> I have a list of dictionaries. They all have the same keys. I want to find >> the >> set of keys where all the dictionaries have the same values. Suggestions? > This one is better: a = {} a['dict'] = 1 b = {} b['dict'] = 2 c = {} c['d

Re: A little morning puzzle

2012-09-19 Thread Antoon Pardon
On 19-09-12 13:17, Neal Becker wrote: > I have a list of dictionaries. They all have the same keys. I want to find > the > set of keys where all the dictionaries have the same values. Suggestions? common_items = reduce(opereator.__and__, [set(dct.iteritems()) for dct in lst]) common_keys = set

Re: A little morning puzzle

2012-09-19 Thread Peter Otten
Dwight Hutto wrote: >> I have a list of dictionaries. They all have the same keys. I want to >> find the >> set of keys where all the dictionaries have the same values. >> Suggestions? > > Here is my solution: > > > a = {} > a['dict'] = 1 > > b = {} > b['dict'] = 2 > > c = {} > c['dict'] =

Re: A little morning puzzle

2012-09-19 Thread Dwight Hutto
> I have a list of dictionaries. They all have the same keys. I want to find > the > set of keys where all the dictionaries have the same values. Suggestions? Here is my solution: a = {} a['dict'] = 1 b = {} b['dict'] = 2 c = {} c['dict'] = 1 d = {} d['dict'] = 3 e = {} e['dict'] = 1 x

Re: A little morning puzzle

2012-09-19 Thread Jussi Piitulainen
Neal Becker writes: > I have a list of dictionaries. They all have the same keys. I want > to find the set of keys where all the dictionaries have the same > values. Suggestions? Literally-ish: { key for key, val in ds[0].items() if all(val == d[key] for d in ds) } -- http://mail.python.org/m

Re: A little morning puzzle

2012-09-19 Thread Peter Otten
Neal Becker wrote: > I have a list of dictionaries. They all have the same keys. I want to > find the set of keys where all the dictionaries have the same values. Suggestions? >>> items = [ ... {1:2, 2:2}, ... {1:1, 2:2}, ... ] >>> first = items[0].items() >>> [key for key, value in first if

A little morning puzzle

2012-09-19 Thread Neal Becker
I have a list of dictionaries. They all have the same keys. I want to find the set of keys where all the dictionaries have the same values. Suggestions? -- http://mail.python.org/mailman/listinfo/python-list