[Tutor] improve the code
Alan Gauld
alan.gauld at btinternet.com
Tue Nov 1 19:07:21 CET 2011
On 01/11/11 14:33, Dave Angel wrote:
> Just use the sort() method of the list object. In particular, items()
> returns an unordered list, so it's ready to be sorted.
>
> for residues, numbers in new_dictionary.items().sort():
I don't think this would work since sort works in place. You would need
to use sorted()
for residues, numbers in sorted(new_dictionary.items()):
And sorted() also works on the Set type object that items returns...
HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list