I wrote an article about python Lists and dictionaries in , Described in the article python The list in is ordered , The dictionary is out of order , Later, some fans reminded me in the group , say python3.6 After the version of , Dictionaries are ordered , therefore , I found a lower version python To verify the effect :
First , Download from official website python3.4 Version of , Then write a line of code to verify all the... Of the print dictionary key. Look at the printed key The order of :
Python3.6 The following versions :( With 3.4 Version as an example )
You don't think you have to use keys() Functions are out of order :
As can be seen from the above figure , Respectively in cmd Windows and pycharm Print dictionary in key value , Find the order of printing and run again in a new window each time , The printing order is inconsistent . also pycharm Will show ,python3.4 The version of is in pycharm Is no longer supported in .
Next, let's look at python3.6 The effect of the above version :( With 3.9 Version as an example )
As can be seen from the above figure , In the new version ,python in the light of key The storage of has become orderly , When traversing and printing , Values will be taken in the order of storage .
One more thing : Previously introduced to , In the dictionary ,key Is the only one. . This is not to say that it is not unique key You're going to report a mistake , Just use the back key and value To cover the front key and value.
a = {'a': 1, 'b': 2, 'b': 3} # No error will be reported during operation
PS: Recently, Xiaobian and other test bosses are sorting out python A series of articles on learning automation and test development from scratch , We all study and discuss with each other in the group , Output learning notes and articles every day , Interested partners can scan the code to join , Learn from each other .
This article is from WeChat official account. - Xiaobo's road to growth (libotest)
The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the [email protected] Delete .
Original publication time : 2021-09-27
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .