Peter Otten a écrit :
> Bruno Desthuilliers wrote:
>
>
>> print >> output, sorted(decorated_lines, reverse=True)[0][1]
>
>
> Or just
>print >> output, max(decorated_lines)[1]
Good point. More explicit, and a bit faster too. Thanks Peter.
--
http://mail.python.org/mailman/l
Bruno Desthuilliers wrote:
> print >> output, sorted(decorated_lines, reverse=True)[0][1]
Or just
print >> output, max(decorated_lines)[1]
Peter
--
http://mail.python.org/mailman/listinfo/python-list
Shawn Milo a écrit :
(snip)
> The script reads a file from standard input and
> finds the best record for each unique ID (piid). The best is defined
> as follows: The newest expiration date (field 5) for the record with
> the state (field 1) which matches the desired state (field 6). If
> there is
Bjoern Schliessmann a écrit :
> Bruno Desthuilliers wrote:
>
>>Shawn Milo a écrit :
>
>
>>>if recs.has_key(piid) is False:
>>
>>'is' is the identity operator - practically, in CPython, it
>>compares memory addresses. You *dont* want to use it here.
>
>
> It's recommended to use "is None";
John Machin a écrit :
> On Mar 3, 12:36 pm, Bruno Desthuilliers >
> [snip]
>
>> DATE = 5
>> TARGET = 6
>
> [snip]
>
>>Now for the bad news: I'm afraid your algorithm is broken : here are my
>>test data and results:
>>
>>input = [
>> #ID STATE ... ... ... TARG DATE
>> "aaa\tAAA
Shawn Milo kirjoitti:
>
> I am not looking for the smallest number of lines, or anything else
> that would make the code more difficult to read in six months. Just
> any instances where I'm doing something inefficiently or in a "bad"
> way.
>
> I'm attaching both the Perl and Python versions, an
On Mar 2, 10:44 pm, "Shawn Milo" <[EMAIL PROTECTED]> wrote:
> I'm new to Python and fairly experienced in Perl, although that
> experience is limited to the things I use daily.
>
> I wrote the same script in both Perl and Python, and the output is
> identical. The run speed is similar (very fast) a
William Heymann <[EMAIL PROTECTED]> writes:
> On Saturday 03 March 2007, Ben Finney wrote:
> > Bjoern Schliessmann <[EMAIL PROTECTED]> writes:
> >
> > if not recs.has_key(piid): # [1]
> >
> Why not
>
> if piid not in recs:
>
> That is shorter, simpler, easier to read and very slightly fas
On Saturday 03 March 2007, Ben Finney wrote:
> Bjoern Schliessmann <[EMAIL PROTECTED]> writes:
>
> if not recs.has_key(piid): # [1]
>
Why not
if piid not in recs:
That is shorter, simpler, easier to read and very slightly faster. Plus you
can change the data structure of recs later with
On Mar 3, 7:08 pm, [EMAIL PROTECTED] wrote:
> On Mar 2, 2:44 pm, "Shawn Milo" <[EMAIL PROTECTED]> wrote:
>
> (snipped)
>
> > I'm attaching both the Perl and Python versions, and I'm open to
> > comments on either. The script reads a file from standard input and
> > finds the best record for each un
In <[EMAIL PROTECTED]>, Bjoern Schliessmann wrote:
> Bruno Desthuilliers wrote:
>> Shawn Milo a écrit :
>
>>> if recs.has_key(piid) is False:
>>
>> 'is' is the identity operator - practically, in CPython, it
>> compares memory addresses. You *dont* want to use it here.
>
> It's recommended
On Mar 2, 2:44 pm, "Shawn Milo" <[EMAIL PROTECTED]> wrote:
(snipped)
> I'm attaching both the Perl and Python versions, and I'm open to
> comments on either. The script reads a file from standard input and
> finds the best record for each unique ID (piid). The best is defined
> as follows: The ne
Bjoern Schliessmann <[EMAIL PROTECTED]> writes:
> Bruno Desthuilliers wrote:
> > Shawn Milo a écrit :
>
> >> if recs.has_key(piid) is False:
> >
> > 'is' is the identity operator - practically, in CPython, it
> > compares memory addresses. You *dont* want to use it here.
>
> It's recommended
Bruno Desthuilliers wrote:
> Shawn Milo a écrit :
>> if recs.has_key(piid) is False:
>
> 'is' is the identity operator - practically, in CPython, it
> compares memory addresses. You *dont* want to use it here.
It's recommended to use "is None"; why not "is False"? Are there
multiple False in
On Mar 3, 12:36 pm, Bruno Desthuilliers >
[snip]
> DATE = 5
> TARGET = 6
[snip]
> Now for the bad news: I'm afraid your algorithm is broken : here are my
> test data and results:
>
> input = [
> #ID STATE ... ... ... TARG DATE
> "aaa\tAAA\t...\t...\t...\tBBB\t20071212\n",
[sn
Here's my version (not tested much). Main differences from yours:
1. It defines a Python class to hold row data, and defines the __cmp__ operation
on the class, so given two Row objects r1,r2, you can say simply
if r1 > r2: ...
to see which is "better".
2. Instead of reading all the rows in
John Machin a écrit :
> On Mar 3, 9:44 am, "Shawn Milo" <[EMAIL PROTECTED]> wrote:
>
(snip)
>
> [big snip]
> Here is my rewrite in what I regard as idiomatic reasonably-modern
> Python (OMMV of course).
(snip)
John, I *swear* I didn't read your code before posting my own version !
--
http://m
Shawn Milo a écrit :
> I'm new to Python and fairly experienced in Perl, although that
> experience is limited to the things I use daily.
>
> I wrote the same script in both Perl and Python, and the output is
> identical. The run speed is similar (very fast) and the line count is
> similar.
>
> N
On Mar 3, 9:44 am, "Shawn Milo" <[EMAIL PROTECTED]> wrote:
> I'm new to Python and fairly experienced in Perl, although that
> experience is limited to the things I use daily.
>
> I wrote the same script in both Perl and Python, and the output is
> identical. The run speed is similar (very fast) an
Few suggestions, some important, some less important. All my
suggestions are untested.
Use 4 spaces to indent.
If you want to speed up this code you can move it inside a function.
After that, if you want to make it even faster you can use Psyco too.
Ho are the dates represented? How do you te
20 matches
Mail list logo