Quick operations on the python list

Source: Internet
Author: User

In C, there is only one way to modify the content of each node in the container: traverse the node and perform operations on the node:

For (int I = 0; I <len; ++ I) {con [I] * = 2 ;}

Some of our C ++ 11 (m is a standard container ):

For (auto I: m) {I * = 2 ;}

Or

Foreach (m. begin (), m. end (), [] (x) {x * = 2 });

Naturally, someone will write in python like this:

For I in m: I = I * 2

If you are still writing like this for pythoner, you can do it in one sentence.

B = [x * 2 for x in a]

The list can be quickly generated in python, or even generated by conditional judgment.

C = [x * 2 for x in a if! = 2]

Well, it's a bit python.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.