While its possible to evaluate a list like that, it's not good practice as evaluating anything can introduce many edge cases.
A better solution would be to have the user input the values of the list either all at once:
entry = list(input("Enter the values: ").split(","))
# User enters: 1,2,3,4,5
# List ends up as: [1, 2, 3, 4, 5]
or one at a time
endChar = '$' # Setting end character
in = '' # Clearing user input variable
chars = [] # List of values
print("Enter your values, use '$' to finish.") # User prompt
while in != endChar: # Continue until $ is entered
in = input("Value: ") # Get value
chars.append(in) # Add element to list
print(chars) # Finished list
Answer from Dan P on Stack OverflowHelp with user input into a list
python - Get a list of numbers as input from the user - Stack Overflow
How can I create a list based on user input? Like having the user name the list and add what values they want inside the list
Adding input to a list
output = [None, None, None] - - - expected output = list of user input
"Write a python file basic_list.py and declare two functions make_list() to return a list of user input while and get_input() to get one input and return it."
this_list = []
def get_input():
int(input("Enter list item "))
def make_list(i):
while i > 0:
this_list.append(get_input())
i -= 1
return this_list
if __name__ == "__main__":
print(make_list(3))
print(make_list(2))
print(make_list(1))
In Python 3.x, use this.
a = [int(x) for x in input().split()]
Example
>>> a = [int(x) for x in input().split()]
3 4 5
>>> a
[3, 4, 5]
>>>
It is much easier to parse a list of numbers separated by spaces rather than trying to parse Python syntax:
Python 3:
s = input()
numbers = list(map(int, s.split()))
Python 2:
s = raw_input()
numbers = map(int, s.split())
Iโm working ok a beginner project for my Coding class where Iโm making a checklist, the only part thatโs stopping me from finishing though is creating the actual check list part, how do I get the user to name and create a list (which will be their checklist) and add whatever values they want to it.