sorting tuples...

nidhog at gmail.com nidhog at gmail.com
Tue Sep 27 22:01:38 EDT 2005


Magnus Lycka wrote:

> Why? It seems you are trying to use a string as some kind of container,
> and Python has those in the box. Just use a list of tuples, rather than
> a list of strings. That will work fine for .sort(), and it's much more
> convenient to access your data. Using the typical tool for extracting
> binary data from files/strings will give you tuples by default.

my problem with tuples & lists is that i don't know how to assign data
to them properly. i'm quite new in python ;)

with the binary stuff out of the way, what i have is this string data:

20050922 # date line
mike
mike's message...
20040825 # date line
jeremy
jeremy's message...
...

what i want to do is to use the date line as the first data in a tuple
and the succeeding lines goes into the tuple, like:

(20050922, mike, mike's message)

then when it matches another date line it makes another new tuple with
that date line as the header data and the succeeding data, etc..

(20050922, mike, mike's message)
(20040825, jeremy, jeremy's message)
...

then i would sort the tuples according to the date.

is there an easier/proper way of doing this without generating alot of
tuples?

thanks! for the help :)




More information about the Python-list mailing list