Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to analyze the data set Dict of python in key-value pair

Shulou Source: shulou.com Published: 2022-06-01 17:40:07 09月24日 Update

How to analyze the data set Dict of python in the key-value pair? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Dict is the abbreviation of dictionary, which, as its name implies, is the type of dictionary. We look up the head of the dictionary first, then find the corresponding number of pages, and then look up the words we want to look up. The number of pages corresponding to this partial radical is the key in dict, and the word we are looking for is value. The essence of dict is that the value of value,key can be any immutable type through key, usually a number and a string (dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys.), and value can be any type.

So under what circumstances should dict be used? In fact, dict is of great use. For example, when the client calls the server-side api through http, the parameter key pair passed is of type dict (called map in java); for example, the student information, the student number is key, and all the student-related information can be stored in the value. Because value can store any type of data, it can also be a nested dict. So value tries not to be too complicated.

Initialize dict, the initial values are included with {}, key and value are separated by:, and key-value pairs are separated by.

Add a new key-value pair, key in [] and value after =

Delete a key-value pair, del d [key]

Access values in dict

If there is no corresponding key, an error will be reported.

Determine whether a key is included in the dict

Get all the key in dict

Get all the value in dict

Key and value in the loop variable dict

The sorted method can be sorted by key

But sorted will return a new dict and will not change the original dict

As mentioned above, the vlaue of dict can be of any type. Let's add a dict of cities to the dict. Here is the nesting of two dict.

Of course, data structures such as List,Set can also be added to dict. When using dict, you should be careful not to nest too many complex data structures, which are difficult to maintain and understand.

This is the answer to the question about how to analyze the data set Dict of python in the key-value pair. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: That is type data analysis problem complexity between information side circle dictionary student data structure method more structure radical number of pages help solution Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Shulou Information Redmi Microsoft