Iteration
This list or tuple can be traversed by a for loop, which we call iteration (iteration) as long as it is an iterative object, whether or not subscript, can iterate, such as dict can iterate:
By default, the Dict iteration is key. What if you want to iterate over value?
For k,v in D.iteritems ():
Print K,v
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9C/24/wKioL1lsj-qxxlW8AACvGbGG1zo364.png "style=" float : none; "title=" 234520170717182019.png "alt=" Wkiol1lsj-qxxlw8aacvgbgg1zo364.png "/>
★ Judge an object to be an iterative object, by judging the iterable type of the collections module
★ Determine if the data type is an iterative data type: strings, lists, sets, dictionaries, tuples are iterative, integer numbers are not iterative.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9C/23/wKioL1lsjdHQpM8FAAG2gJ3uocU970.png "title=" 234520170717180302.png "alt=" Wkiol1lsjdhqpm8faag2gj3uocu970.png "/>
List-Generated
List generation is a very simple, yet powerful, built-in Python build that can be used to create lists
-Generates the square of all even numbers within 100;
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9C/24/wKiom1lsj-qwWaADAAB2oeHyHSY812.png "style=" float : none; "title=" 234520170717181950.png "alt=" Wkiom1lsj-qwwaadaab2oehyhsy812.png "/>
-Generate ' ABC ' and ' 123 ' in full alignment;
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9C/24/wKioL1lsj-nxN7MUAAApuaQn-3g651.png "style=" float : none; "title=" 234520170717181937.png "alt=" Wkiol1lsj-nxn7muaaapuaqn-3g651.png "/>
-Lists all files and directory names in the current directory; < reference: Os.listdir (".") >
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9C/24/wKioL1lsknjgEDziAACGoMWwVFw930.png "title=" 234520170717183224.png "alt=" Wkiol1lsknjgedziaacgomwwvfw930.png "/>
-Generates the contents of the dictionary, formatted as ' Key=value ', and returns its list format;
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9C/24/wKiom1lsj-ngJq4eAABiS2zqDOM717.png "style=" float : none; "title=" 234520170717181926.png "alt=" Wkiom1lsj-ngjq4eaabis2zqdom717.png "/>
-Change all the strings in the list to lowercase letters < reference: S.lower () >
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9C/24/wKiom1lsj-iw26DhAAB6fjvs1FE731.png "title=" 234520170717181902.png "style=" Float:none; "alt=" Wkiom1lsj-iw26dhaab6fjvs1fe731.png "/>
Enumeration method Reference variable: (enumerate)
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9C/25/wKiom1lsnWyQ6gRkAADLTenpsLM419.png "title=" 234520170717190451.png "style=" Float:none; "alt=" Wkiom1lsnwyq6grkaadltenpslm419.png "/>
Fou Loop reference variable:
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9C/25/wKiom1lsnW2SsATPAADPtS6Zbq0551.png "title=" 234520170717190503.png "style=" Float:none; "alt=" Wkiom1lsnw2ssatpaadpts6zbq0551.png "/>
Generator
Through the list generation, we can directly create a list, limited by memory, the list capacity is certainly limited; Create a list of 1 million elements, occupy a large amount of storage space;
What are the subsequent elements in the process of the cycle? This eliminates the need to create a complete list, saving a lot of space. In Python, this side loop computes the mechanism, called the Generator (Generator)
How do I create a generator? Change a list-generated [] to ()
Use the G.next () method to read the element sequentially (trouble)
Use for loop (recommended)
Understand the essence of the generator, how to implement the function of generative function by functions when the problem cannot be expressed by the list generating type.
Python programming: The famous Fibonacci sequence (Fibonacci), in addition to the first and second numbers, any number can be added by the first two numbers: 1, 1, 2, 3, 5, 8,, seven,...
The ★FIB function defines the calculation rules for the Fibonacci sequence, starting with the first element and extrapolating any subsequent elements, which are very similar to the generator logic. To turn the FIB function into a generator, just change print B to yield B. generator
★ Function Order execution, return when the return statement or the last line function statement.
The generator function executes at each call to next (), encounters a yield statement, and executes again from the yield statement that was last returned.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9C/25/wKioL1lsnW-yAAbqAADBVPQHIbg157.png "title=" 234520170717190536.png "style=" Float:none; "alt=" Wkiol1lsnw-yaabqaadbvpqhibg157.png "/>
[Object Object]
# 4). Implement the builder manually
#定义一函数fib, Implement the Fibonacci sequence (Fibonicci):
# 1, 1, 2, 3, 5, 8, .....
#
# def FIB (n):
#
# Execution: fib (3) output: 1,1,2
# Execution: fib (4) output: 1,1,2,3
650) this.width=650; "Src=" https://s5.51cto.com/ Wyfs02/m01/9c/25/wkiom1lsnw7xeq7waadf2jw98xy940.png "title=" 234520170717190528.png "style=" Float:none; "alt=" Wkiom1lsnw7xeq7waadf2jw98xy940.png "/>
# 5). Implementing single-threaded concurrency with yield
# asynchronous I/O model epoll http Nginx tomcat
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9C/25/wKiom1lsnXGi-GuoAAEVF6bcWkA995.png "title=" 234520170717190608.png "style=" Float:none; "alt=" Wkiom1lsnxgi-guoaaevf6bcwka995.png "/>
Program:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9C/25/wKioL1lsnXCBKp5QAAGLVVCTNoo770.png "title=" 234520170717190548.png "style=" Float:none; "alt=" Wkiol1lsnxcbkp5qaaglvvctnoo770.png "/>