Sorting dict keys

Roberto Bonvallet rbonvall at gmail.com
Sat Jul 21 01:44:37 CEST 2007


On 20 jul, 19:34, montyphy... at gmail.com wrote:
> copy.copy returns a new object:
>
> >>> copy.copy(a.keys())
>
> [1,2,3]
>
> Then why doesn't copy.copy(a.keys()).sort() work??

It works, but you don't notice it, because you don't save a reference
to the new list.
Try this:

  c = copy.copy(a.keys())
  c.sort()

--
Roberto Bonvallet




More information about the Python-list mailing list