Sorting a list
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Feb 1 15:58:31 EST 2007
John Salerno a écrit :
> Bruno Desthuilliers wrote:
>
>> You don't tell how these lines are formatted, but it's possible that
>> you don't even need a regexp here. But wrt/ sorting, the list of
>> tuples with the sort key as first element is one of the best solutions.
>
>
> Ah, so simply using sort() will default to the first element of each tuple?
Yes. Then on the second value if the first compares equal, etc...
> The citations are like this:
>
> lastname, firstname. (year). title. other stuff.
Then you theoretically don't even need regexps:
>>> line = "lastname, firstname. (year). title. other stuff."
>>> line.split('.')[1].strip().strip('()')
'year'
But since you may have a dot in the "lastname, firstname" part, I'd
still go for a regexp here just to make sure.
More information about the Python-list
mailing list