James Stroud <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > James Stroud <[EMAIL PROTECTED]> wrote:
> >...
> >
> >>def doit(rows, doers, i=0):
> >> for r, alist in groupby(rows, itemgetter(i)):
> >> if len(doers) > 1:
> >> doit(alist, doers[1:], i+1)
> >> doers[0](r)
>
Alex Martelli wrote:
> James Stroud <[EMAIL PROTECTED]> wrote:
>...
>
>>def doit(rows, doers, i=0):
>> for r, alist in groupby(rows, itemgetter(i)):
>> if len(doers) > 1:
>> doit(alist, doers[1:], i+1)
>> doers[0](r)
>
>
> Isn't this making N useless slices (thus copies, for
Alex Martelli wrote:
> James Stroud <[EMAIL PROTECTED]> wrote:
>...
>
>>def doit(rows, doers, i=0):
>> for r, alist in groupby(rows, itemgetter(i)):
>> if len(doers) > 1:
>> doit(alist, doers[1:], i+1)
>> doers[0](r)
>
>
> Isn't this making N useless slices (thus copies, for
James Stroud <[EMAIL PROTECTED]> wrote:
...
> def doit(rows, doers, i=0):
>for r, alist in groupby(rows, itemgetter(i)):
> if len(doers) > 1:
>doit(alist, doers[1:], i+1)
> doers[0](r)
Isn't this making N useless slices (thus copies, for most kinds of
sequences) for a doer
Frank Millman <[EMAIL PROTECTED]> wrote:
> Benji York wrote:
> > Frank Millman wrote:
> > > reader = csv.reader(open('trans.csv', 'rb'))
> > > rows = []
> > > for row in reader:
> > > rows.append(row)
> >
> > Why do you create a list of rows instead of just iterating over the
> > reader direct
Benji York wrote:
> Frank Millman wrote:
> > reader = csv.reader(open('trans.csv', 'rb'))
> > rows = []
> > for row in reader:
> > rows.append(row)
>
> Why do you create a list of rows instead of just iterating over the
> reader directly?
> --
> Benji York
A - didn't think of it - good idea
John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 14/06/2006 8:38 AM, Robert Kern wrote:
> > Gary Herron wrote:
> >> John Machin wrote:
> >>
> >>> On 13/06/2006 6:28 PM, Paul McGuire wrote:
> >>>
> (Oh, and I like groupby too! Combine it with sort to quickly create
On 14/06/2006 8:38 AM, Robert Kern wrote:
> Gary Herron wrote:
>> John Machin wrote:
>>
>>> On 13/06/2006 6:28 PM, Paul McGuire wrote:
>>>
(Oh, and I like groupby too! Combine it with sort to quickly create
histograms.)
# tally a histogram of a list of values from 1-10
dat
Gary Herron wrote:
> John Machin wrote:
>
>>On 13/06/2006 6:28 PM, Paul McGuire wrote:
>>
>>>(Oh, and I like groupby too! Combine it with sort to quickly create
>>>histograms.)
>>>
>>># tally a histogram of a list of values from 1-10
>>>dataValueRange = range(1,11)
>>>data = [random.choice(dataVa
On 14/06/2006 8:06 AM, Gary Herron wrote:
> John Machin wrote:
>> On 13/06/2006 6:28 PM, Paul McGuire wrote:
>>
>>
>>> (Oh, and I like groupby too! Combine it with sort to quickly create
>>> histograms.)
>>>
>>> # tally a histogram of a list of values from 1-10
>>> dataValueRange = range(1,11)
John Machin wrote:
> On 13/06/2006 6:28 PM, Paul McGuire wrote:
>
>
>> (Oh, and I like groupby too! Combine it with sort to quickly create
>> histograms.)
>>
>> # tally a histogram of a list of values from 1-10
>> dataValueRange = range(1,11)
>> data = [random.choice(dataValueRange) for i in xr
On 13/06/2006 6:28 PM, Paul McGuire wrote:
> (Oh, and I like groupby too! Combine it with sort to quickly create
> histograms.)
>
> # tally a histogram of a list of values from 1-10
> dataValueRange = range(1,11)
> data = [random.choice(dataValueRange) for i in xrange(1)]
>
> hist = [ (k,le
Not related to itertools.groupby, but the csv.reader object...
If for some reason you have malformed CSV files, with embedded newlines
or something of that effect, it will raise an exception. To skip those,
you will need a construct of something like this:
raw_csv_in = file('filenamehere.csv')
fo
James Stroud wrote:
> Frank Millman wrote:
>
>> Hi all
>>
>> This is probably old hat to most of you, but for me it was a
>> revelation, so I thought I would share it in case someone has a similar
>> requirement.
>>
>> I had to convert an old program that does a traditional pass through a
>> sorte
Frank Millman wrote:
> Hi all
>
> This is probably old hat to most of you, but for me it was a
> revelation, so I thought I would share it in case someone has a similar
> requirement.
>
> I had to convert an old program that does a traditional pass through a
> sorted data file, breaking on a chan
Frank Millman wrote:
> reader = csv.reader(open('trans.csv', 'rb'))
> rows = []
> for row in reader:
> rows.append(row)
Why do you create a list of rows instead of just iterating over the
reader directly?
--
Benji York
--
http://mail.python.org/mailman/listinfo/python-list
Frank;
I would just like to thank-you for this timely post.
I am working on a reporting project that needed "groupby" functionality
and I was going to sit down this morning to rework some "very ugly
code" into some "not quite so ugly code".
Your post got me pointed to in the "right" direction and
Paul McGuire wrote:
> >
> > reader = csv.reader(open('trans.csv', 'rb'))
> > rows = []
> > for row in reader:
> > rows.append(row)
> >
>
> This is untested, but you might think about converting your explicit "for...
> append" loop into either a list comp,
>
> rows = [row for row in reader]
>
> reader = csv.reader(open('trans.csv', 'rb'))
> rows = []
> for row in reader:
> rows.append(row)
>
This is untested, but you might think about converting your explicit "for...
append" loop into either a list comp,
rows = [row for row in reader]
or just a plain list constructor:
Hi Frank
This is one of the reasons why I love Python, you can write readable
code.
I strive to write clean code but I find that exception handling code
e.g. try:
makes my code ugly and significantly harder to read. Does anyone have
any good
pointers for a former C++ / Perl coder.
/vpr
Frank Mi
Hi all
This is probably old hat to most of you, but for me it was a
revelation, so I thought I would share it in case someone has a similar
requirement.
I had to convert an old program that does a traditional pass through a
sorted data file, breaking on a change of certain fields, processing
each
21 matches
Mail list logo