a question regarding conciseness
Sean 'Shaleh' Perry
shalehperry at attbi.com
Wed Feb 20 15:15:46 EST 2002
>
> for i in d.keys().sort():
> do something
>
> I get:
>
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> TypeError: loop over non-sequence
>
> But I know that d.keys() returns a list to which the sort() function should
> be applicable.
Yes keys() returns a sequence. However sort() is a method of that sequence and
does not return anything.
mylist = alist.sort() # also an invalid statement
You could write a sort() function so that
for i in sort(d.keys()):
do something
would work.
More information about the Python-list
mailing list