I posted it in commemoration because it triggered the update of python. It's a language that is currently being updated.
--Referenced site
By the way, the operation check is Python3.7.3-> Python3.8.5.
Very convenient!
However, when printing with `` pprint```, the benefit is not so good due to the **
pprint``` ** sort before output ** specification.
test1.py
from pprint import pprint
d = {1: 10, 9: 90, 3: 30, 7: 70, 5: 50}
print(d)
pprint(d)
out1
{1: 10, 9: 90, 3: 30, 7: 70, 5: 50}
{1: 10, 3: 30, 5: 50, 7: 70, 9: 90}
The same applies when substituting one by one.
test2.py
from pprint import pprint
d2 = {}
d2[0] = 0
d2[8] = 80
d2[2] = 20
d2[6] = 60
d2[4] = 40
print(d2)
pprint(d2)
out2
{0: 0, 8: 80, 2: 20, 6: 60, 4: 40}
{0: 0, 2: 20, 4: 40, 6: 60, 8: 80}
`sort_dicts = False``` can be specified for
`pprint``` in python3.8 or laterFrom python3.8, it seems that the `sort_dicts``` option has been added to
pprint```. The default is ``
sort_dicts = True, so if you want to keep the order, you need to specify `` `False
.
test3.py
from pprint import pprint
d = {1: 10, 9: 90, 3: 30, 7: 70, 5: 50}
print(d)
pprint(d, sort_dicts=False)
out3
{1: 10, 9: 90, 3: 30, 7: 70, 5: 50}
{1: 10, 9: 90, 3: 30, 7: 70, 5: 50}
Recommended Posts