Re: letter frequency counter / your thoughts..

2008-05-07 Thread castironpi
On May 7, 5:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On 7 mai, 23:51, "[EMAIL PROTECTED]"<[EMAIL PROTECTED]> wrote: > > (snip) > > Small improvement thanks to Paul Rubin: > > from collections import defaultdict > from operator import itemgetter > > def get_letters_frequency(source):

Re: letter frequency counter / your thoughts..

2008-05-07 Thread [EMAIL PROTECTED]
On 7 mai, 23:51, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: (snip) Small improvement thanks to Paul Rubin: from collections import defaultdict from operator import itemgetter def get_letters_frequency(source): letters_count = defaultdict(int) for letter in source: letters_cou

Re: letter frequency counter / your thoughts..

2008-05-07 Thread [EMAIL PROTECTED]
On 7 mai, 23:50, Paul Rubin wrote: (snip) > Someone else suggested the heapq module, which is a good approach > though it might be considered a little bit high-tech. If you > want to use sorting (conceptually simpler), you could use the > sorted function instead of the i

Re: letter frequency counter / your thoughts..

2008-05-07 Thread John Machin
On May 8, 6:00 am, [EMAIL PROTECTED] wrote: > That's a great suggestion Arnaud. I'll keep that in mind next time I > post code. Thanks ;) > It's a suggestion for YOUR benefit, not ours. Consider keeping it in mind next time you WRITE code, whether you intend publishing it or not. -- http://mail.

Re: letter frequency counter / your thoughts..

2008-05-07 Thread [EMAIL PROTECTED]
On 7 mai, 18:39, [EMAIL PROTECTED] wrote: > Hello, > > Here is my code for a letter frequency counter. It seems bloated to > me and any suggestions of what would be a better way (keep in my mind > I'm a beginner) would be greatly appreciated.. > > def valsort(x): > res = [] > for k

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Paul Rubin
[EMAIL PROTECTED] writes: > def valsort(x): > res = [] > for key, value in x.items(): > res.append((value, key)) > return res Note: all code below is untested and may have errors ;-) I think the above is misnamed because it doesn't actually sort. Anyway, you could

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Paul Hankin
On May 7, 5:39 pm, [EMAIL PROTECTED] wrote: > Here is my code for a letter frequency counter.  It seems bloated to > me and any suggestions of what would be a better way (keep in my mind > I'm a beginner) would be greatly appreciated.. Yours is a little more efficient than this, but here's a compa

Re: letter frequency counter / your thoughts..

2008-05-07 Thread umpsumps
That's a great suggestion Arnaud. I'll keep that in mind next time I post code. Thanks ;) On May 7, 12:27 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > Hello, > > > Here is my code for a letter frequency counter. It seems bloated to > > me and any suggestions o

Re: letter frequency counter / your thoughts..

2008-05-07 Thread castironpi
On May 7, 1:31 pm, "Ian Kelly" <[EMAIL PROTECTED]> wrote: > On Wed, May 7, 2008 at 11:30 AM, Paul Melis <[EMAIL PROTECTED]> wrote: > >     dic = {} > >     for letter in strng: > >         if letter not in dic: > >             dic[letter] = 0 > >         dic[letter] += 1 > > As a further refinement

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Ian Kelly
On Wed, May 7, 2008 at 11:30 AM, Paul Melis <[EMAIL PROTECTED]> wrote: > dic = {} > for letter in strng: > if letter not in dic: > dic[letter] = 0 > dic[letter] += 1 As a further refinement, you could use the defaultdict class from the collections module: di

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > Hello, > > Here is my code for a letter frequency counter. It seems bloated to > me and any suggestions of what would be a better way (keep in my mind > I'm a beginner) would be greatly appreciated.. > > def valsort(x): > res = [] > for key, value in x.item

Re: letter frequency counter / your thoughts..

2008-05-07 Thread castironpi
On May 7, 12:30 pm, Paul Melis <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Here is my code for a letter frequency counter.  It seems bloated to > > me and any suggestions of what would be a better way (keep in my mind > > I'm a beginner) would be greatly appreciated.. > > Not bad for

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Paul Melis
[EMAIL PROTECTED] wrote: Here is my code for a letter frequency counter. It seems bloated to me and any suggestions of what would be a better way (keep in my mind I'm a beginner) would be greatly appreciated.. Not bad for a beginner I think :) def valsort(x): res = [] for key

letter frequency counter / your thoughts..

2008-05-07 Thread umpsumps
Hello, Here is my code for a letter frequency counter. It seems bloated to me and any suggestions of what would be a better way (keep in my mind I'm a beginner) would be greatly appreciated.. def valsort(x): res = [] for key, value in x.items(): res.append((value,