The list itself is input, so how can I get it entered?

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

x = [1, 3, 5] This is the input value, but what I've learned so far is map, split, and so on, I can only enter the values listed in this way 135, but I don't know how to input the list itself.

python list

2022-09-19 23:22

2 Answers

The question is ambiguous. Please write a part of the code and ask me what you want to do specifically. For example, if you are entering a function, you can do this.

def do_something_with(a):
    print(f'a : {a}')

def showlist(l=[]):
    for item in l:
        print(item)

    a,b,c = l
    do_something_with(a)    

mylist = [1,2,3]
showlist(mylist)        


2022-09-19 23:22

import json
a = input()    # "[1, 2, 3, 4, 5]"
b = json.loads(a)
print(b)
>> [1, 2, 3, 4, 5]


2022-09-19 23:22

If you have any answers or tips


© 2022 pinfo. All rights reserved.