> But for sorting the list with the first element as key, I tried it
using
just mylist.sort() without the lambda, and its working also. Then why
use the lambda?
There is a little difference between those two variations.
Example:
>>> sorted([[1,2],[1,3],[1,1]])
[[1, 1], [1, 2], [1, 3]]
>>> s
Lie Ryan wrote:
if you have data like this:
mylist = [
[3, 4, 3, 2, 1],
[2, 1, 1, 1, 1],
[4, 2, 2, 1, 2],
[1, 3, 1, 1, 1],
]
you can use mylist.sort(key=lambda x: x[0])
sorted(mylist, key=lambda x: x[0]) works as well if you need a new list
I have a further question. If I wa
On Sun, Sep 13, 2009 at 1:17 AM, Lie Ryan wrote:
> if you have data like this:
> mylist = [
> [3, 4, 3, 2, 1],
> [2, 1, 1, 1, 1],
> [4, 2, 2, 1, 2],
> [1, 3, 1, 1, 1],
> ]
>
> you can use mylist.sort(key=lambda x: x[0])
You can omit the key parameter completely in this case, unless yo
On Sun, Sep 13, 2009 at 7:27 AM, Rich Lovely wrote:
> 2009/9/13 Lie Ryan :
> > Wayne wrote:
> >>
> > if your data is like this:
> > mylist = [
> >[3, 2, 4, 1],
> >[4, 1, 2, 3],
> >[3, 1, 2, 1],
> >[2, 1, 1, 1],
> >[1, 1, 2, 1],
> > ]
> >
> > you can use zip(*mylist) to transfo
2009/9/13 Lie Ryan :
> Wayne wrote:
>>
>> Hi,
>>
>> I have a set of data that looks something like this:
>>
>> 3, 4, 3, 2, 1
>> 2, 1, 1, 1, 1
>> 4, 2, 2, 1, 2
>> 1, 3, 1, 1, 1
>>
>> I want to be able to sort it by the first column, keeping the rest of the
>> values in the same position relative to
Wayne wrote:
Hi,
I have a set of data that looks something like this:
3, 4, 3, 2, 1
2, 1, 1, 1, 1
4, 2, 2, 1, 2
1, 3, 1, 1, 1
I want to be able to sort it by the first column, keeping the rest of
the values in the same position relative to the original:
1, 3, 1, 1, 1
2, 1, 1, 1, 1
3, 4, 3,
Hi,
I have a set of data that looks something like this:
3, 4, 3, 2, 1
2, 1, 1, 1, 1
4, 2, 2, 1, 2
1, 3, 1, 1, 1
I want to be able to sort it by the first column, keeping the rest of the
values in the same position relative to the original:
1, 3, 1, 1, 1
2, 1, 1, 1, 1
3, 4, 3, 2, 1
4, 2, 2, 1, 2