Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use list derivation in python

Shulou Source: shulou.com Published: 2022-06-01 05:42:10 11月11日 Update

This article mainly shows you the "list guide in python how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "list guide in python how to use" this article.

List derivation

Of all the bizarre grammars, list deductions should be used the most frequently, and the simplification of the code is also obvious. For example, to find the square of each element of a list, you should usually write like this (of course, there are other ways to write it, such as using the map function):

> a = [1,2,3,4,5] > > result = list () > for i in a:result.append (iTuni) > result [1,4,9,16,25]

If you use list derivation, it looks much more comfortable:

> a = [1,2,3,4,5] > > result = [iTuni for i in a] > > result [1,4,9,16,25] are all the contents of this article entitled "how to use list derivation in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Content articles learning help eccentric obvious highest strange comfortable bizarre code elements writing functions effects easy to understand more organization knowledge ribbon Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Docker NVidia Linux Shulou Tech Info