Re: [Tutor] Sorting more than one list

2005-04-01 Thread Alan Gauld
> Yikes! Alan must have been up too late. They are not the same at all. > Alan's code creates a list containing *every combination* of one > element from each source list: Oops! Blush... Lack of testing I'm afraid, I checked the syntax worked but not the actual results! Thing is, I knew about zip

Re: [Tutor] Sorting more than one list

2005-04-01 Thread Kent Johnson
Max Noel wrote: On Apr 1, 2005, at 09:59, Alan Gauld wrote: Since the data are obviously related (since you need to keep them linked), I'd be inclined to merge the lists into a list of tuples merged = [(a,b,c,d) for a in l1 for b in l2 for c in l3 for d in l4] Then you can sort 'merged' and it shou

Re: [Tutor] Sorting more than one list

2005-04-01 Thread Max Noel
On Apr 1, 2005, at 09:59, Alan Gauld wrote: Since the data are obviously related (since you need to keep them linked), I'd be inclined to merge the lists into a list of tuples merged = [(a,b,c,d) for a in l1 for b in l2 for c in l3 for d in l4] Then you can sort 'merged' and it should just work

Re: [Tutor] Sorting more than one list

2005-04-01 Thread Alan Gauld
> I need to sort 4 lists but I need that they make the "sort together". > I'll sort just one but when I change the position of the items of the > 1st list I have to change the positions of the other 3 lists. Can I do > this just using the sort() method of the list object? > If I can't, someone know

RE: [Tutor] Sorting more than one list

2005-03-31 Thread Tony Meyer
> What's b.index(x) do? > > I'm guessing the for a list Delta = ["a,"b","c"], you get > > Delta.index("b") > > 1 > > Am I right? Yes. For future use, the easiest way to answer a question like that is to do: >>> help([].index) Help on built-in function index: index(...) L.index(value,

Re: [Tutor] Sorting more than one list

2005-03-31 Thread Liam Clarke
What's b.index(x) do? I'm guessing the for a list Delta = ["a,"b","c"], you get Delta.index("b") 1 Am I right? On Apr 1, 2005 1:16 PM, py <[EMAIL PROTECTED]> wrote: > > > An alternative way of doing this (if you have python 2.4): > > >>> ppl = ['john', 'mary', 'lary', 'jane'] > >>> age

Re: [Tutor] Sorting more than one list

2005-03-31 Thread py
An alternative way of doing this (if you have python 2.4): >>> ppl =   ['john', 'mary', 'lary', 'jane']>>> age =   [15, 30, 23, 25]>>> height= [160, 165, 178, 170]>>> sortby = lambda a, b: [a[b.index(x)] for x in sorted(b)]>>> sortby(ppl, age)['john', 'lary', 'jane', 'mary']>>> sortby(ppl, height)[

Re: [Tutor] Sorting more than one list

2005-03-30 Thread Kent Johnson
Diego Galho Prestes wrote: Hi! I need to sort 4 lists but I need that they make the "sort together". I'll sort just one but when I change the position of the items of the 1st list I have to change the positions of the other 3 lists. Can I do this just using the sort() method of the list object? You

Re: [Tutor] Sorting more than one list

2005-03-30 Thread Max Noel
On Mar 31, 2005, at 04:19, Diego Galho Prestes wrote: Hi! I need to sort 4 lists but I need that they make the "sort together". I'll sort just one but when I change the position of the items of the 1st list I have to change the positions of the other 3 lists. Can I do this just using the sort() met

Re: [Tutor] Sorting more than one list

2005-03-30 Thread Brian van den Broek
Brian van den Broek said unto the world upon 2005-03-30 18:28: Diego Galho Prestes said unto the world upon 2005-03-30 21:19: Hi! I need to sort 4 lists but I need that they make the "sort together". I'll sort just one but when I change the position of the items of the 1st list I have to change the

Re: [Tutor] Sorting more than one list

2005-03-30 Thread Brian van den Broek
Diego Galho Prestes said unto the world upon 2005-03-30 21:19: Hi! I need to sort 4 lists but I need that they make the "sort together". I'll sort just one but when I change the position of the items of the 1st list I have to change the positions of the other 3 lists. Can I do this just using the s

[Tutor] Sorting more than one list

2005-03-30 Thread Diego Galho Prestes
Hi! I need to sort 4 lists but I need that they make the "sort together". I'll sort just one but when I change the position of the items of the 1st list I have to change the positions of the other 3 lists. Can I do this just using the sort() method of the list object? If I can't, someone know a si