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 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 no record matching the desired state, then just take the
> > newest expiration date.
>
> > Thanks for taking the time to look at these.
>
> My attempts:
>
>
> ### Python (re-working John's code) ###
>
> import sys
>
> def keep_best(best, current):
>
> ACTUAL_STATE = 1
> # John had these swapped
> DESIRED_STATE = 5
> EXPIRY_DATE = 6
*Bullshit* -- You are confusing me with Bruno; try (re)?reading what
the OP wrote (and which you quoted above):
"""
The newest expiration date (field 5) for the record with
the state (field 1) which matches the desired state (field 6).
"""
and his code (indented a little less boisterously):
"""
#If the current record is the correct state
if current.split("\t")[1] == current.split("\t")[6]:
#If the existing record is the correct state
if best.split("\t")[1] == best.split("\t")[6]:
#If the new record has a newer exp. date
if current.split("\t")[5] > best.split("\t")[5]:
"""
--
http://mail.python.org/mailman/listinfo/python-list