Built-in functions for Python dictionaries

Source: Internet
Author: User
Tags shallow copy

In []: Test=dict (x=1,y=2,z=3) in [71]: testout[71]: {'x': 1,'y': 2,'Z': 3}in [[a=[]:'a','b','C']in [[b=[1,2,3]:]in [74]: Zip (A, b) out[74]: [('a', 1), ('b', 2), ('C'-R)]in [75]: dict (Zip (A, b)) out[75]: {'a': 1,'b': 2,'C': 3}
dict.clear ()    Delete all the elements in the Dictionary dict.copy ()    Returns a copy of the dictionary (shallow copy) Dict.fromkeys (seq,val=None)    Creates and returns a new dictionary that is the key to the dictionary in the SEQ element, and Val does the initial value for all keys in the dictionary (default is None if this value is not provided) Dict.get (Key,default=None)    For the key in the dictionary dict, return the value corresponding to it, if the dictionary does not exist return Nonedict.has_key (key)    if the key (key) exists in the dictionary, returns True, otherwise returns False.dict.items ()    returns a list containing a dictionary (key, value) to a tuple Dict.keys ()    Returns a list containing the keys in the Dictionary Dict.iteritems () returns a dictionary element an iteration Dict.iterkeys () Returns a dictionary key iteration dict.itervalues () returns a dictionary of value iterations Dict.pop (Key[,default])    and a method get () similar to if the key key exists in the dictionary, deletes and returns Dict[key], Throws a Keyerror exception if the key key does not exist and does not give the default value. Dict.popitem ()    randomly deletes a key from the dictionary-value is similar todict.setdefault (Key,default=none)    and Method set (), If the key key does not exist in the dictionary,it is assigned a value by dict[key]= default. Dict.update (DICT2) adds a    dictionary dict2 key - value pair to the dictionary dictdict.values ()    Returns a list that contains all the values in the dictionary

Built-in functions for the 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.