ranjan das wrote:
> I have the following list
>
> List=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL',
> 'R9'),
> ('G4', 'CFS', 'FCL', 'R10' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R4' ),
> ('G1',
> 'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R5') ]
>
>
> now I want to gro
You are right, lambda lis: lis[1:3] would be more readable
2011/3/30 Sander Sweers
> On 30 March 2011 00:30, Alan Gauld wrote:
> > Wouldn't you just return a tuple of the two elements?
> >
> > Or am I missing something having jumped into the middle of the thread...
>
> Ah yes, you are correct.
On 30 March 2011 00:30, Alan Gauld wrote:
> Wouldn't you just return a tuple of the two elements?
>
> Or am I missing something having jumped into the middle of the thread...
Ah yes, you are correct. But imo reading "key=lambda l: (l[1], l[0],
l[2])" (which would be needed to sort how the OP want
"Sander Sweers" wrote
flexible, readable and elegant than using a lamda. How would you
sort
on the first and last item with lambda?
Wouldn't you just return a tuple of the two elements?
Or am I missing something having jumped into the middle of the
thread...
Alan G.
__
>From python docs:
For non-negative indices, the length of a slice is the difference of the
indices, if both are within bounds. For example, the length of word[1:3] is
2.
Example:
>>> list_[1][1:3]
('LOOSEFREIGHT', 'MIXEDLCL')
>>>
As I said i think my approach is more pythonic, but I'm not abso
2011/3/29 Rafael Durán Castañeda :
> And more pythonic, I think
I don't agree :-). I think itemgetter from the operator module is more
flexible, readable and elegant than using a lamda. How would you sort
on the first and last item with lambda?
Greets
Sander
__
On 29 March 2011 23:52, Sander Sweers wrote:
> On 29 March 2011 22:03, ranjan das wrote:
>> New_List=[ [ ( 'G1', 'CFS', 'FCL', 'R1' ), ('G1', 'CFS', 'FCL', 'R2' ),
>> ('G4', 'CFS', 'FCL', 'R10' ) ], [ ('G2', 'LOOSEFREIGHT', 'LCL', 'R4' ),
>> ('G2', 'LOOSEFREIGHT', 'LCL', 'R5' )], [ ('G3', 'LOOSE
This would work nice too:
list_=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL',
'R9'), ('G4', 'CFS', 'FCL', 'R10' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R4' ),
('G1', 'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R5') ]
>>> sorted(list_,key=lambda l: l[1:3])
[('G1', 'CFS', 'FC
On 29 March 2011 22:03, ranjan das wrote:
> List=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL', 'R9'),
> ('G4', 'CFS', 'FCL', 'R10' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R4' ), ('G1',
> 'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R5') ]
>
>
> now I want to group this eleme
On 3/29/2011 4:03 PM, ranjan das wrote:
I have the following list
List=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL',
'R9'), ('G4', 'CFS', 'FCL', 'R10' ), ('G2', 'LOOSEFREIGHT', 'LCL',
'R4' ), ('G1', 'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL',
'R5') ]
now I want
I have the following list
List=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL', 'R9'),
('G4', 'CFS', 'FCL', 'R10' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R4' ), ('G1',
'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R5') ]
now I want to group this elements of List first by inde
11 matches
Mail list logo