[Tutor] advanced sorting

Noufal Ibrahim noufal at airtelbroadband.in
Tue Sep 4 21:30:44 CEST 2007


chinni wrote:
> 
> 
> In Advance Sorting by giving the keywords to sort the list.But, iam 
> getting the fallowing errors
> 
>  >>> x = ['srikanth', 'kumar', 'muppandam', 'will', 'be', 'a']
>  >>> x.sort(key=len)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: sort() takes no keyword arguments
>  >>> x.sort(reverse=True)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: sort() takes no keyword arguments
> 
> 

Seems to work fine for me. What version of Python are you using?

 >>> x=['srikanth', 'kumar', 'muppandam', 'will', 'be', 'a']
 >>> x.sort(reverse=True)
 >>> x
['will', 'srikanth', 'muppandam', 'kumar', 'be', 'a']
 >>>

-- 
~noufal


More information about the Tutor mailing list