Example Analysis of List Comprehension in python
This article shares with you the content of the sample analysis of List Comprehension in python. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
List Comprehension
List Comprehension gives us an elegant way to create lists based on other lists. The following code snippet creates a new list by multiplying each element of the old list by 2.
# Multiplying each element ina list by 2 original_list = [1 Multiplying each element ina list by 2 for x in original_list 3 Magne 4] new_list = [2 rect x for x in original_list] print (new_list) # [2 Jing 4 Jing 6 Jo 8] Thank you for your reading! This is the end of this article on "sample Analysis of List Comprehension in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!