Python-list comprehension

Source: Internet
Author: User

List comprehension

Using a list comprehension:[x for x in iterable] to create list instance

[Expresion for x in Iterabel] lists the core of the derivation in expression.

1 #!/usr/bin/env Python32 #-*-coding:utf-8-*-3 ############################4 #File Name:test_list_comprehension.py5 #Author:frank6 #Mail: [email protected]7 #Created time:2018-05-29 20:33:568 ############################9 ImportNumPy as NPTen  OneSeed = 123 A  - #Analog Data Set labels - #generate random numbers based on seed theRDG =np.random.RandomState (Seed) - #sir, a random number matrix of 5 rows and 2 columns. -X = Rdg.rand (5,2) - #each time a row is taken, judging if two numbers and less than 1, give a value of 1; If two numbers and not less than 1, assign a value to a + #[expression for x in Iterable] -Y = [[Int (x0+x1<1)] for(X0,X1)inchX] + Print("x:{}". Format (X)) A Print("y:{}". Format (Y))

The list-pushing derivation has a strong extensibility, and expression differs, and the functions that can be executed are quite different.

Python-list comprehension

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.