[Tutor] 4.7.5

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Jan 20 10:39:41 CET 2014


On 20/01/2014 01:16, Doug and Riekie Dorman wrote:
> I think I may have found a bug:
>
>>>>pairs  =  [(1,  'one'),  (2,  'two'),  (3,  'three'),  (4,  'four')]
>>>>pairs.sort(key=lambda  pair:  pair[1])
>>>>pairs
> [(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]
>
> Should be:
>
>>>>pairs  =  [(1,  'one'),  (2,  'two'),  (3,  'three'),  (4,  'four')]
>>>>pairs.sort(key=lambda  pairs:  pairs[1])
>>>>pairs
> [(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]
>
> I have increased the size of the two s's to show the problem.
>
> Doug
>

What has the name you've given your lambda parameter got to do with the 
name of your list?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list