简体   繁体   中英

inputing [ 0 10 20 40 ] for exemple as argument for array in python

I know there are other ways, for example:

from array import *
arr = array("i", list(map(int, input("Give an array : ").split())))

I am not using Numpy library but if there is a way to do this, it will be helpful.

The Output I am looking for is (In the Console):

Array1: [ 0 10 20 40 60]
Array2: [10, 40]
Common values between two arrays are:
[10 40]

I know the code for comparision but the one i don't kno is how to define an array from inputing this: [ 0 10 20 40 60]

Would this helps? (then you can do Array2 and set() operation as earlier posts suggested).


    >>> Array1 = [int(x) for x in input('Enter a few numbers to creat Array: ').split()]
    Enter a few numbers to creat Array: 0 10 20 40 60
    >>> Array1
    [0, 10, 20, 40, 60]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM