[Tutor] question on lists
Sean 'Shaleh' Perry
shalehperry@attbi.com
Sat, 7 Sep 2002 14:33:35 -0700
On Saturday 07 September 2002 13:49, Martin Klaffenboeck wrote:
> Hello,
>
> I have got a list with 4 columns. This 4 columns are:
>
> string1 string2 id timestamp
>
> So how do I store the data? As a list or as an array:
>
a list is for all intents and purposes an array in python. There are 3=20
grouping structures in core python -- tuple, list, dictionary. A tuple i=
s a=20
list which can not be changed once created a dictionary is equivalent to=20
perl's hash or C++'s map.
> What I want to do with this data:
>
> Sort the list alphabetically (if possible _not_ case sensitive).
> Add new entries at the right alphabetic position.
>
> Randomize the list (or a copy of it) and sort it back alphabetically
> after modifying the id and the timestamp.
>
>
list.sort() takes a function to determine sort order. There is a handy=20
function called cmp() which is often used for this.
Your add function is not too hard to write and the random module may give=
you=20
what you want for the random stuff.
Read through the python docs on lists and the builtin functions it should=
get=20
you started.