In <mailman.8231.1395103693.18130.python-l...@python.org> Chris Angelico 
<ros...@gmail.com> 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
gor...@panix.com    watch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to