In <[email protected]> Chris Angelico
<[email protected]> writes:
> > Is there a way to force a certain ordering of the printout or else
> > somehow manage to get at least a certain stable ordering of the
> > printout (i.e. input and output are identical)?
> Yes; instead of simply printing it out (which calls repr()),
> explicitly iterate over it, like this:
> def display(d):
> return '{'+','.join('%r: %r'%(key,d[key]) for key in sorted(d))+'}'
You could also use the OrderedDict type, which is subclass of dict that
preserves insertion order.
--
John Gordon Imagine what it must be like for a real medical doctor to
[email protected] watch 'House', or a real serial killer to watch 'Dexter'.
--
https://mail.python.org/mailman/listinfo/python-list