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)