Python input one-dimensional array (enter a line spaced in spaces)

Source: Internet
Author: User

Two ways (Verify syntax errors in Ok,python2 in Python3)

# Method 1  for inch input (). Split ()] # method two num = list (map (int, input (). Strip (). Split ()))print num
Input: 1 2 3 output: [1, 2, 3]

Usage of map in Python
The three maps (), filter (), and reduce () in Python are built-in functions that are applied to the sequence, highlighting some common uses of the map

## The func acts on each element of the SEQ and returns the result of all calls as a list

Some common uses:

Convert tuples to list***>>> map (int,))[1, 2, 3]Converts a string into a list***>>> map (int,'1234')[1, 2, 3, 4]Extract the key from the dictionary and store the result in a list ***>>> map (int, {1:2,2:3,3:4})[1, 2, 3]The string converts the Narimoto group and returns the result as a list of ***>>> map (tuple,'AGDF')[('a',), ('g',), ('D',), ('F',)]#turn lowercase into uppercasedefu_to_l (s):returnS.upper ()PrintMap (u_to_l,'ASDFD')

Python input one-dimensional array (enter a line spaced in spaces)

Related Article

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.