Re: Moderator please remove [Re: Better way to do this dict comprehesion]

2017-04-01 Thread Skip Montanaro
Passed along to postmas...@python.org, who generally takes care of this sort of thing. Skip On Apr 1, 2017 11:19 AM, "Steve D'Aprano" wrote: > Can one of the mailing list moderators please remove this person's post for > including a link to an anti-Semitic video by

Moderator please remove [Re: Better way to do this dict comprehesion]

2017-04-01 Thread Steve D'Aprano
Can one of the mailing list moderators please remove this person's post for including a link to an anti-Semitic video by David Duke? On Sat, 1 Apr 2017 07:13 pm, Robert L. wrote: Goyim were born [...] web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld[...]

Re: Better way to do this dict comprehesion

2017-04-01 Thread Robert L.
On 3/7/2017, Sayth Renshaw wrote: > I have got this dictionary comprehension and it > works but how can I do it better? > > from collections import Counter > > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k, v) for k,v in counts.items() if v % 3 == 0] > return a[0][0]

Re: Better way to do this dict comprehesion

2017-03-08 Thread Jussi Piitulainen
Sayth Renshaw writes: >> To find an unpaired number in linear time with minimal space, try >> stepping through the list and either adding to a set or removing from >> it. At the end, your set should contain exactly one element. I'll let >> you write the actual code :) >> >> ChrisA > > ChrisA the

Re: Better way to do this dict comprehesion

2017-03-08 Thread Jussi Piitulainen
Sayth Renshaw writes: > Peter I really like this > > The complete code: > from collections import Counter def find_it(seq): > ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] > ... return result You confirmed to Chris that you want the item that occurs an

Re: Better way to do this dict comprehesion

2017-03-08 Thread Peter Otten
Sayth Renshaw wrote: > Peter I really like this > > The complete code: > from collections import Counter def find_it(seq): > ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] > ... return result > ... test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]

Re: Better way to do this dict comprehesion

2017-03-08 Thread Sayth Renshaw
Peter I really like this The complete code: >>> from collections import Counter >>> def find_it(seq): ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] ... return result ... >>> test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] >>> find_it(test_seq) But what

Re: Better way to do this dict comprehesion

2017-03-08 Thread Peter Otten
Sayth Renshaw wrote: > Hi > > I have got this dictionary comprehension and it works but how can I do it > better? List comprehensions (that's what you have) are nice, but overused. > from collections import Counter > > def find_it(seq): > counts = dict(Counter(seq)) There is no need

Re: Better way to do this dict comprehesion

2017-03-07 Thread Sayth Renshaw
> > But the given problem states there will always only be one number appearing > > an odd number of times given that is there a neater way to get the answer? > > Take a step back for a moment. Are you trying to find something that > appears an odd number of times, or a number of times that

Re: Better way to do this dict comprehesion

2017-03-07 Thread Chris Angelico
On Wed, Mar 8, 2017 at 1:55 PM, MRAB wrote: > Using Counter seems like a simpler way to me. I wouldn't bother about other > ways unless that way wasn't "good enough" for some reason. Maybe. But without being sure what the goal is, it's hard to say. ChrisA --

Re: Better way to do this dict comprehesion

2017-03-07 Thread MRAB
On 2017-03-08 02:37, Chris Angelico wrote: On Wed, Mar 8, 2017 at 1:28 PM, Sayth Renshaw wrote: I have got this dictionary comprehension and it works but how can I do it better? from collections import Counter def find_it(seq): counts = dict(Counter(seq)) a

Re: Better way to do this dict comprehesion

2017-03-07 Thread Chris Angelico
On Wed, Mar 8, 2017 at 1:28 PM, Sayth Renshaw wrote: > I have got this dictionary comprehension and it works but how can I do it > better? > > from collections import Counter > > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k, v) for k,v in

Better way to do this dict comprehesion

2017-03-07 Thread Sayth Renshaw
Hi I have got this dictionary comprehension and it works but how can I do it better? from collections import Counter def find_it(seq): counts = dict(Counter(seq)) a = [(k, v) for k,v in counts.items() if v % 3 == 0] return a[0][0] test_seq =