python--Dictionary

Source: Internet
Author: User

Also known as a hash table

Common dictionary built-in methods

Dict.clear ()

Dict.fromkeys ()

# Create a new dictionary with the key of the dictionary in sequence seq, Val for the dictionary all keys corresponding to the initial value >>> list =[1,2,3]>>> dict =  Dict.fromkeys (list)>>> dict{1:none, 2:none, 3: None}>>> dict = Dict.fromkeys (list,1)>>> dict{1:1, 2:1, 3:1}
Dict.get (Key, Default=none)    # Returns the value of the specified key if the value does not return the default value in the dictionary
Dict.has_key (key)    # returns False if the key returns true in the dictionary dict
Dict.items ()    # Returns an array of traversed (key, value) tuples in a list
Dict.keys ()    # Returns a dictionary of all keys in a list
Dict.values ()    # returns all values in the dictionary as a list
Dict.setdefault (Key, Default=none)    # is similar to get (), but if the key does not already exist in the dictionary, the key will be added and the value will be set to default

Dict.update ()

# update the key/value pairs of the dictionary dict2 to dict >>> Dict1 = {1:'a'}>>> dict2 = { 2:'b'}>>> dict1.update (dict2)>>> dict1{  'a'b'}

python--Dictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.