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:
one, iterative protocol : can be iterated to meet the requirements is called an iterative protocol. Internal implementation of the __ITER__ methodIterable: An iterative------corresponding flagWhat does iteration mean? : Takes a value as a for
I am the happy porter: Http://gulu-dev.com/post/perf_assist/2016-12-20-unity-coroutine-optimizing#toc_0------------------------------------------------------------------------Split Line------------------------------------ ----------------------------
In Python, all collections can be iterated, and within the Python language, iterators are used to supportFor loopBuilding and extending collection typesTraverse a text file line by rowList derivation, dictionary derivation, and set derivationTuple
1. foreach statement
The C # compiler converts the foreach statement to the methods and properties of the IEnumerable interface.
Copy Code code as follows:
foreach (person p in persons)
{
Console.WriteLine (P);
}
The
This article is a learning note for the Liaoche Python tutorialSpecific content, you can refer to the following links:http://www.liaoxuefeng.com/ 1. Slice (Slice)
Intercept a section from a list, tuple, or string.[i:j: K] means to remove part of the
can iterate over objects
Iterative Protocol
We are now analyzing the reason for the result, which can be "iterative" for the loop, but if you're thinking about, for how do you know who is iterative?
If we write a data type ourselves and hope that
The variables in Java are divided into two categories: local variables and class variables. A local variable is a variable defined within a method, such as a variable defined in the Run method. For these variables, there is no question of sharing
Generator
Iterators
Built-in functions
Homework
First, generator1.1. List GeneratorProblem Introduction: See List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], I ask you to add 1 to each value in the tableProgramme one:A = [1,3,4,6,7,7,8,9,11]for
One, iterative objects and iterators1. The concept of iterationThe result of the last output is the initial value of the next input, and the repeating process is called an iteration, one iteration at a time, and the result of each iteration is the
List-GeneratedNow there's a need to look at the list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and ask you to add 1 to each value in the table, how do you do that? You might think of 2 waysTwo-Force Youth edition>>> a[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> b = []>>>
Both the comprehensions and the generations syntax in Python are used for iteration. The comprehensions syntax can be used on list,set,dictionary, while generations syntax is divided into generator functions and generator
Review the For loop in PythonIf you use an index to take a value, you can take the value anywhere, if you want to know where the value is.If we use a for loop to get the value, we take each value, do not need to care about the location of each value,
List-GeneratedTo generate [1x1, 2x2, 3x3, ..., 10x10]>>> [x * x for x in range (1, 11)]The For loop can also be followed by an if judgment>>> [x * x for x in range (1, one) if x% 2 = = 0][4, 16, 36, 64, 100] You can also use the two-layer loop to
1. Can iterate:When we printPrint (dir ([up])) can be seen in the results that appear with' __iter__ ', this method, #次协议叫做可迭代协议A function that contains the ' __iter__ ' method is an iterative functionstrings, lists, tuples, dictionaries, and
4 Advanced Features 4.1 slices [:] * Note:--list and tuple, string all support slicing4.2 Iterations iteration for ... in and for ... in ifTwo variable iterations, for inch [(1, 1), (2, 4), (3, 9)]: Results 1 1--2 4--3 9Example 2: Dictionary >>>d={'
"" "1, the generator is Object 2, each time the next () method is called to return a value until the Stopiteration exception 3 is thrown, how to create a generator? Simply write a normal function and include the yield statement instead of the return
1. IteratorThe simplest example of a iterator should be an array subscript, and look at the following C + + code:
Copy Code code as follows:
int array[10];
for (int i = 0; i printf ("%d", array[i]);
The iterator works in
1. Sliced Slice
Slice operator: eg. L[0:3], takes the index 0,1,2 element, does not include 3. L[-1] takes the penultimate element. L[:10:2] Take the first 10 elements and take them once every two times.
You can perform slice operations on list,
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.