list of lists

Max M maxm at mxm.dk
Wed Sep 17 02:18:05 EDT 2003


Peter Otten wrote:

> Nice explanation. I take the occasion to warn newbies that the sort() method 
> is a showstopper in this scheme:
> 
> getArray().sort()[3].formatter() #BAD CODE, DON'T USE
>              ^
>              |
>              + -- sort() returns None
> 
> By the way, is there any Python programmer who has not made this error at
> least once?


Also it is a slower approach if you want to look up more than one item 
in the list. In that case it is better to bind the sorted result of 
getArray to a variable.

arr = getArray()
arr.sort()
arr[3].formatter()
arr[4].formatter()
arr[5].formatter()


So I find that I rarely use the short form of the expression.

regards Max M





More information about the Python-list mailing list