dictionaryDict.pop ()Dict.get (' key ') gets the value of a key from the dictionaryDict.has_key (' key ')CollectionThe collection is divided into mutable set (set) and immutable set (Frozenset)Set hash, Frozenset non-hash (infrequently used)Set is a non-repeating set of elements that support Union (union), intersection (intersection), difference (differential set), and sysmmetric difference (symmetric difference sets), and other mathematical operations1. Definition set (SET)A = set (' Aasdfsdfa
'}>>> A{1: ' One ', 2: ' Both ', 3: ' Three ', 4: ' Four ', 5: ' Five '}>>> b{1: ' One ', 2: ' Both ', 3: ' Three ', 4: ' Four '}Pop ()Popitem () Random Popup>>> A.pop (2)' Both '>>> A{1: ' One ', 3: ' Three ', 4: ' Four ', 5: ' Five '}>>> A.popitem ()(5, ' five ')>>> A{1: ' One ', 3: ' Three ', 4: ' Four '}>>> A.setdefault(7, ' seven ')' Seven '>>> A{1: ' One ', 3: ' Three ', 4: ' Four ', 7: ' Seven '}>>> B = {7: ' SEVEN '}>>> A{1: ' One ', 3: ' Three ', 4: ' Four ', 7: ' Seven '}>>> A.update
pairDict ([' Tim ', 123), (' Tiny ', 234)]) >>>{' Tiny ': 234, ' Tim ': 123}Derivation creates a dictionary:{d2:d2+ ' @main. com ' for D2 in List (D.keys ()}}>>>{' Jack ': ' [email protected] ', ' Tom ': ' [email protected] '}Exercise: A key-value pair in a circular output dictionary:For Name,email in D.items ():Print (Name,email)4. CollectionEmpty collection: A = set () ※ to create an empty collection, you must use Set ()Demonstrate:Basket = {' Appl
Problem: Look for two dictionaries in the middle of the same place (same key, same value, etc.)Solution: Use the keys () or the items () method to perform common collection operations (such as seek a set, intersection, and difference sets)>>> a={'x': 1,'y': 2,'Z': 3}>>> b={'ww': 10,'x': 11,'y': 2}>>> A.keys () B.keys () #键的交集 {'y','x'}>>> A.keys ()-B.keys () #键的差集 {'Z'}>>> A.keys () |B.keys () #键的并集 {'ww','y','x','Z'}>>> A.items () B.items () {('y', 2
1. DictionariesDict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}Dictionary converted to string, return: Print type (str (dict)), str (DICT)Dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')Print tuple (dict)#字典能够转为元组, return: (7, ' Zara ', ' first ')Print tuple (dict.values ())Dictionary to list. return: [' age ', ' nam
database#用字典建立一个项目管理数据库Project, key-project name, value contains two dictionaries A and b,key A-project number key B-Project cost#我们可以使用直接写键值项的方式建立字典, but the amount of data is too large, in order to be concise, first set up lists A and B, respectively, the Dictionary DA and DB, and then through Project keyword parameters P1 and p2 form a large dictionary projec
This article illustrates the common method of Python merging two dictionaries with efficiency comparisons. Share to everyone for your reference. The specific analysis is as follows:
The following code illustrates 5 methods of merging two dictionaries and makes a simple performance test
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The
Common Operations on lists, strings, and dictionaries in python.
The list operation is as follows:
A = ["haha", "xixi", "baba"]
Increment: a. append [gg]
A. insert [1, gg] To the place marked as 1, add gg
Delete: a. remove (haha) deletes the first matched haha from left to right in the list.
Del a. [0] Delete the value corresponding to 0 as the subscriptA. NO content is written in the pop (0) brackets. The
Original address: Http://docs.pythontab.com/python/python3.4/datastructures.html#tut-tuplesThe best way to understand a dictionary is to think of it as an unordered key: a set of value pairs (Key:value pairs) whose keys must be distinct (within the same dictionary).A pair of curly braces creates an empty dictionary: {}
One. Basic use:1. Assignment: {Key:value}1.1 In the same place as the list: changes in the value associated with the index (key) are changed1.2 Different from the list: regardless of the length of the value, and the list is ordered to consider the end of the offset, more than the end of the offset will be an error.2. Len (dictionary): Returns the number of keysTwo. Method of the Dictionary:1. Take out all v
The Basics tutorial introduces basic concepts, especially objects and classes.
The Advanced tutorial further expands the basic tutorial to illustrate the details of Python. Hopefully, after the advanced tutorials, you have a more comprehensive understanding of python.
As we said before, the list is a class in Python. A specific table, such as NL = [1,3,8], is a
'}dict1[' age '] = 18# modify agedict1[' School '] = "DPS School" # ADD new ENTRYPR Int ("Age:", dict1[' age ') print ("School:", dict1[' School ']) #输出结果Age: 18School: DPS SchoolGet () returns the Val corresponding to key, if key does not exist, returns noneDict1 = {' Name ': ' King ', ' age ': +, ' Class ': ' 2-9 '}print ("Age:", Dict1.get ("Age")) #输出结果Age: 21Fromkeys (SEQ, value)Seq = (' name ', ' age ', ' sex ') dict = Dict.fromkeys (seq, "value") print ("New
Python basics, operators, lists, dictionaries, nesting, traversal, functionsOperator: +–*///%Self-increasing self-reduction squared self-removal ....Comparison Operators! = Not equal to = = equals Eg:a = 1 B = 3 alogical operator or OR and and notLinux hit code fill CTRL + NIf you need to be aware of the point indentation, add the following:Linux edit error can jump directly past the method VI file name + w
Classical Dictionary use functionDict: A dictionary is created from a sequence of other mappings (such as other dictionaries) or (keys, values). Of course dict become a function is not very exact, it is essentially a type. Like List.
Copy Code code as follows:
items=[(' name ', ' Zhang '), (' Age ', 42)]
D=dict (items)
d[' name ']
Le
A sequence in Python is a contiguous memory space used to store multiple values, similar to an array in the C languageThe commonly used sequence structure is a list, a tuple, a dictionary, a string, a collection, etc.Unordered sequence: Dictionary, collectionOrdered sequence: list, tuple, string, support bidirectional index (the first element is labeled 0, the la
flexible data structure in Python.basic operation of the dictionary>>>d = {' spam ': 2, ' Ham ': 1, ' Eggs ': 3}>>>d[' spam '] value via key2>>>d{' spam ': 2, ' Ham ': 1, ' Eggs ': 3}>>>len (d) Length3>>> ' Ham ' in D membersTrue>>>list (D.keys ()) converts the dictionary key to list[' Eggs ', ' ham ', ' spam ']Modify dictionary in situ>>>d[' ham '] = [' Grill '
The following small series for everyone to bring a based on the Python Ganso and dictionaries and sets of superficial understanding. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
One, Ganso (tuple)
1. The meta-ancestor is not modifiable, usually written in parentheses in a series of items, the position of the order
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.