Python has three built-in data structures: list, ancestor, and Dictionary. This article introduces these three data structures and provides examples, let's take a closer look at the differences between the three.
1. list)
List is the data structure that processes a group of ordered projects. you can store a series pr
defined, it's immutable? Why did you change it later? Don't worry, let's take a look at the definition when the tuple contains 3 elements: when we change the list element ' A ' and ' B ' to ' X ' and ' Y ', the tuple becomes: on the surface, The elements of a tuple do change, but not the elements of a tuple., but the elements of the list. The list that the tupl
list, consisting of a series of elements arranged in a particular order. You can create a list of all the letters, numbers, 0~9, or names of all family members in the alphabet, or you can add anything to the list, where there is no relationship between the elements. In Python
#python List‘‘‘There are many ways to create a list:1. Create an empty list:[with one square bracket]2. Use a pair of brackets, with ', ' to separate the elements inside: [A, B, C], [a]3.Using a
Tuple, list, dict, and pythontuple in Python
------------------------------- Updating --------------------------------------
Tuple ):
Tuples are commonly represented by parentheses (). The elements are identified by commas.
1 # define a tuple 2 3 # tuple = 'A', 4 5 tuple = ('A', 'B', 'C', 'D', 'E ', 'F', 'G') 6 7 # In general, after defining a tuples, you cannot add or modify the elements of the tuples,
Tag: Indicates a disadvantage associated with a slice element in the case of an Operation collectionFirst, List1. An ordered set of arbitrary objects A list is a set of values of any type, combined in a certain order. 2. Read by offset The values that make up the list are called elements (Elements). Each element is identified by an index, the first index is 0, and the function of the sequence can be impleme
Python implementation compares the two list ranges, pythonlist
One question: compare two lists. If the list contains values, TRUE is returned; otherwise, FALSE is returned. The detailed questions are as follows:
Create a function, this function extends es two lists as parameters, each
:
>>> [1,2,3]+[4,5,6]
[1, 2, 3, 4, 5, 6]
>>> ' Hello. ' + ' world! '
' hello.world! '
>>> [1,2,3]+ ' world! '
Traceback (most recent call last):File "[1,2,3]+ ' world! 'Typeerror:can only concatenate list (not "str") to List
Multiplication
Multiplying the number x by a sequence produces a new sequence, and in the new sequence the original sequence is repeated x times
Co
() again on the list.? Use the function Len () to quickly learn the length of a list? Traverse List? Magicians = [' Alice ', ' David ', ' Carolina ']? For magician in Magicians:? Print (magician)? For value in range (1,5):Print (value)//printing number 1-4? Numbers = List (range (1,6))Print (numbers)//store 1-5 of num
1. List generation is one of the most popular syntax for Python, with a simple syntax to filter a set of elements and to convert the resulting elements into a syntax format: for inch if condition]EquivalentResul = [] for in collection: if(condition): Result.appen (exp)Example: Ask 1 to 10 of even squares, the code is as follows:Li = [x*x for in if x%2==0]print (LI)Results: [4, 16, 36, 64, 100]Exp
list derivation, below is my test results in Ipython (test environment Python 2.7.10):
>>> long_list = range(1000)>>> a = []>>> %timeit for i in long_list: a.append(i+1)10000 loops, best of 3: 100 µs per loop>>> %timeit [i+1 for i in long_list]10000 loops, best of 3: 43.3 µs per loopA little more efficient, to see the DIS module.
Python does not like FP, and
Use Python to create your Eclipse
Although the Eclipse advanced script environment (IDEA) project is still under development, you must acknowledge that it is very powerful, which allows us to quickly build our own Eclipse development environment.
Based on the powerful Eclipse framework, you can use its built-in plug-in system to fully expand Eclipse. However, writing and deploying a new plug-in is still ve
In all of Python's data structures, list is important and convenient, and this article is mainly about the advanced application of list lists, and the basics can be viewed in blogs.
This article is a translated version of the Python English document, you can also view the English version:
https://docs.python.org/2/tutorial/datastructures.html
Use a
List Parsing
Let's take a look at the following example, which is to get the square of each integer from 1 to 9 and print the result in the list
>>> Power2 = []>>> for i in Range (1,10): ... Power2.append (i*i) ... >>> power2[1, 4, 9, 16, 25, 36, 49, 64, 81]
Python has a very interesting function, that is, list pa
This article mainly introduces the application details of python dict, set, list, And tuple. For more information, see this article, the tuple application and corresponding examples help readers understand its concepts and principles. The details are as follows:
1. Dictionary (dict)
Dict surrounded {}Dict. keys (), dict. values (), dict. items ()Hash (obj) returns the hash value of obj. If it is returned,
The Python list is a more important Python data type, as described below:First, create a listList1=[' A ', ' B ', ' C ', ' d ']list2=[' 1 ', ' 2 ', ' 3 ', ' 4 ']list3=[' sports ', ' News ', ' mnt ', ' Mile ']Lists, like some Linux data types, are accessed starting from 0.Second, access to the
This article is a detailed introduction of Python in the list of the advanced functions, interested in the small partners can refer to
Use a list as a stack: #像栈一样使用列表
stack = [3, 4, 5] stack.append (6) stack.append (7) Stack [3, 4, 5, 6, 7] Stack.pop () #删除最后一个对象 7 Stack [3, 4, 5, 6] stack.p OP () 6 Stack.pop () 5 Stack [3, 4]
Use a
List of knowledge points1. Create a listAssign a value to a variable a list shape such as: List = []the list is empty and can be solid such as: List_name =[' Ergou ', ' Goudan ', ' Xiaolizi ']2. Operation of the listEverything you create
an integer, float (x) converts x to a floating-point number complex (real [, Imag]) creates a complex number str (x) to convert the object x to a string repr (x) to convert the object x to the expression string eval (St R) is used to calculate a valid Python expression in a string and returns an object tuple (s) converts the sequence s to a tuple list (s) converts the sequence s to a
;> list1 = [1,9,3,7,2,6,0]>>> list1.sort()>>> list1[0, 1, 2, 3, 6, 7, 9]>>> list1.sort(reverse=True) >>> list1[9, 7, 6, 3, 2, 1, 0]
Len () gets the sequence length>>> len(list1)7
Max () Gets the maximum value of the sequence>>> max(list1)9
Min () Gets the minimum value of the element>>> min(list1)0
List () applies to all types of sequences. Strings cannot be modified like lists, so it is sometimes useful to
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.