<div dir="ltr"><div><div>Now that dicts are order-preserving, maybe we should change prettyprint:<br><br><span style="font-family:monospace,monospace">In [7]: d = {'one':1, 'two':2, 'three':3}<br><br>In [8]: print(d)<br>{'one': 1, 'two': 2, 'three': 3}</span><br><br></div>order preserved.<br><div><br><span style="font-family:monospace,monospace">In [9]: pprint.pprint(d)<br>{'one': 1, 'three': 3, 'two': 2}</span><br><br></div><div>order not preserved ( sorted, I presume? )<br><br></div><div>With arbitrary order, it made sense to sort, so as to always give the same "pretty" representation. But now that order is "part of" the dict itself, it seems prettyprint should present the preserved order of the dict.<br><br></div><div>NOTE: I discovered this making examples for an intro to Python class -- I was updating the part where I teach that dicts do not preserve order. I was using iPython, which, unbeknownst to me, was using pprint under the hood, so got a different order depending on whether I simply displayed the dict (which used pprint) or called str() or repr() on it. Pretty confusing.<br></div><div><br></div>Will changing pprint be considered a breaking change?<br><br></div>-Chris<br><div class="gmail_extra"><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>