In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to write Python code for you, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Python calls in daily work is still very practical, only need the Python function on it, if you do not know much about Python code, then you must first learn the following pair, the following Python code for systematic analysis and research.
After removing the work of replacing meaningful statements with obscure, nested expressions, a natural question is: "Why?!" All my descriptions of FP are done using Python code. But the most important feature-- and probably the most useful feature in a specific situation.
It eliminates side effects (or at least some containment in specific areas, such as oneness). Most program errors-- and problems that prompt programmers to turn to debugging to solve-- occur because variables contain unexpected values during program execution. Function programs simply do not assign values to variables at all, thus avoiding this special problem.
Let's look at a fairly common piece of command code. Its purpose is to print a list of pairs of numbers whose product is greater than 25. The numbers that make up the pairs themselves are selected from the other two lists. This operation is similar to what programmers actually do in their program segments.
The command method to do this is as follows: the project is too small to go wrong. But our goal may be embedded in code that accomplishes many other purposes at the same time. Those parts annotated with "more stuff" are places where side effects can lead to errors.
In any of these places, the variables xs, ys, bigmuls, x, y may get unexpected values in the hypothetical abridged code. Also, after executing this piece of code, all variables may have values that the code may or may not need later.
Obviously, you can use function / instance form encapsulation and scope considerations to prevent this type of error. Also, you can always del variables after they are executed. But in practice, these pointing types of errors are very common. The functional method of the target completely eliminates these side-effect errors. Here is a possible piece of code:
Bigmuls = lambda xs,ys: filter (lambda (xPowery): Xfanty > 25, combine (xs,ys)) combine = lambda xs,ys: map (None, xs*len (ys), dupelms (ys,len (xs) dupelms = lambda lst N: reduce (lambda srecinct, map (lambda lmenagenn: [l] * n, lst)) print bigmuls ((1, 2, 3), (10, 15, 3, 22)
In the example, we bind the anonymous Python code to the name, but this is not necessarily necessary. We can just nest definitions. This is done for readability purposes; but it is also because combine () is a good utility function available everywhere (a list of all element pairs generated from two input lists).
The subsequent dupelms () is mainly a way to help combine () work. Even though this function example is more verbose than the command example, once you consider that the utility function can be reused, the new code in bigmuls () itself may be less than the code in the command version.
The real advantage of this function example is that no variable will ever change any of its values. There are no possible unforeseen side effects in later code (nor in earlier code). Obviously, having no side effects does not guarantee that the code is correct, but even so, it is an advantage. Note, however, that Python code (unlike many functional languages)
You cannot prevent rebinding of the names bigmuls, combine, and dupelms. If combine () starts to make other sense later in the program, all previous efforts will be wasted. You can gradually build a Singleton class to contain this type of immutable binding (for example, s.bigmuls, etc.); however, this column does not cover this.
On how to write Python code to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.