On Wed, Dec 31, 2008 at 10:54 AM, MRAB wrote:
> Occasionally someone posts here wanting to count items and solutions
> involving dict or defaultdict are suggested, and I think that a 'bag' class
> would be useful. The 'set' class was introduced first in a module, but it
> soon became a builtin. My
On Wed, Dec 31, 2008 at 10:49 AM, Steven D'Aprano
wrote:
> What set module?
Sorry I must have meant the collections module :)
> Adding a multi-set or bag class to the collections module would be a good
> idea though. Perhaps you should put in a feature request?
:) Perhaps I will.
cheers
James
James Mills wrote:
On Wed, Dec 31, 2008 at 10:22 AM, John Machin wrote:
(snip)
The "crawl through the shrubbery looking for evidence" approach
stumbles on the actual code:
Yes I found his implementation soon after :)
Not bad actually... I wonder why bag() isn't
shipped with the std lib - per
On Wed, 31 Dec 2008 10:29:14 +1000, James Mills wrote:
> On Wed, Dec 31, 2008 at 10:22 AM, John Machin
> wrote: (snip)
>
>> The "crawl through the shrubbery looking for evidence" approach
>> stumbles on the actual code:
>
> Yes I found his implementation soon after :) Not bad actually... I
> wo
On Wed, Dec 31, 2008 at 10:22 AM, John Machin wrote:
(snip)
> The "crawl through the shrubbery looking for evidence" approach
> stumbles on the actual code:
Yes I found his implementation soon after :)
Not bad actually... I wonder why bag() isn't
shipped with the std lib - perhaps in teh set
mod
On Dec 31, 10:58 am, "James Mills"
wrote:
> On Wed, Dec 31, 2008 at 9:15 AM, MRAB wrote:
>
> (snip)
>
> > A while back I posted a Python implementation of 'bag' (also called a
> > multiset). The code would then become something like:
>
> What complexity is this ?
The "armchair philosopher" appro
On Wed, Dec 31, 2008 at 9:15 AM, MRAB wrote:
(snip)
> A while back I posted a Python implementation of 'bag' (also called a
> multiset). The code would then become something like:
What complexity is this ?
cheers
James
--
http://mail.python.org/mailman/listinfo/python-list
James Mills wrote:
On Tue, Dec 30, 2008 at 7:10 PM, Roel Schroeven
wrote:
Hm, you just changed an O(n) algorithm to an O(n**2) algorithm. No big
deal for short strings, but try your solution on a string with length
1 and see the difference. On my computer the O(n) version takes
0.008 second
On Tue, Dec 30, 2008 at 7:10 PM, Roel Schroeven
wrote:
> Hm, you just changed an O(n) algorithm to an O(n**2) algorithm. No big
> deal for short strings, but try your solution on a string with length
> 1 and see the difference. On my computer the O(n) version takes
> 0.008 seconds, while your
James Mills schreef:
> Ross, the others have informed you that you are not
> actually incrementing the count. I'll assume you've
> fixed your function now :) ... I want to show you a far
> simpler way to do this which takes advantage of
> Python's list comprehensions and mappings (which are
> reall
On Dec 29, 8:02 pm, Steven D'Aprano wrote:
> On Mon, 29 Dec 2008 17:38:36 -0800, Ross wrote:
> > On Dec 29, 8:07 pm, Scott David Daniels wrote:
> >> Ross wrote:
> >> > ... Use get to write histogram more concisely. You should be able to
> >> > eliminate the if statement.
>
> >> > def histogram(s)
On Mon, 29 Dec 2008 17:38:36 -0800, Ross wrote:
> On Dec 29, 8:07 pm, Scott David Daniels wrote:
>> Ross wrote:
>> > ... Use get to write histogram more concisely. You should be able to
>> > eliminate the if statement.
>>
>> > def histogram(s):
>> > d = dict()
>> > for c in s:
>> >
On Tue, Dec 30, 2008 at 11:43 AM, James Mills
wrote:
> On Tue, Dec 30, 2008 at 11:38 AM, Ross wrote:
>> I realize the code isn't counting, but how am I to do this without
>> using an if statement as the problem instructs?
>
> I just gave you a hint :)
Ross:
This exercise is a simple exercise de
On Tue, Dec 30, 2008 at 11:38 AM, Ross wrote:
> I realize the code isn't counting, but how am I to do this without
> using an if statement as the problem instructs?
I just gave you a hint :)
cheers
James
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 29, 8:07 pm, Scott David Daniels wrote:
> Ross wrote:
> > ... Use get to write histogram more concisely. You should be able to
> > eliminate the if statement.
>
> > def histogram(s):
> > d = dict()
> > for c in s:
> > d[c]= d.get(c,0)
> > return d
>
> > This code returns
On Tue, Dec 30, 2008 at 11:32 AM, James Mills
wrote:
> Ross, the others have informed you that you are not
> actually incrementing the count. I'll assume you've
> fixed your function now :) ... I want to show you a far
> simpler way to do this which takes advantage of
> Python's list comprehension
On Tue, Dec 30, 2008 at 11:00 AM, Ross wrote:
> I am teaching myself Python by going through Allen Downing's "Think
> Python." I have come across what should be a simple exercise, but I am
> not getting the correct answer. Here's the exercise:
>
> Given:
>
> def histogram(s):
>d = dict()
>
Ross wrote:
... Use get to write histogram more concisely. You should be able to
eliminate the if statement.
def histogram(s):
d = dict()
for c in s:
d[c]= d.get(c,0)
return d
This code returns a dictionary of all the letters to any string s I
give it but
On Mon, 29 Dec 2008 17:00:31 -0800, Ross wrote:
> Here's my code:
>
> def histogram(s):
> d = dict()
> for c in s:
> d[c]= d.get(c,0)
> return d
>
> This code returns a dictionary of all the letters to any string s I give
> it but each corresponding value is incor
19 matches
Mail list logo