OiO.lk Blog python How do I create a list from user input? The input will be something like: 1, 2, 3, 4, 5, 6 and then will be turned into a list without the spaces/,
python

How do I create a list from user input? The input will be something like: 1, 2, 3, 4, 5, 6 and then will be turned into a list without the spaces/,


I am trying to create a list from user input.

When the user enters something like "a,b,c,d,e,f" and if I turn that into a list directly, the list will look like ['a', ',', 'b', ',', 'c', ',', 'd', ',', 'e', ',', 'f']. However, naturally, I want it to be just [a,b,c,d,e,f]. How do I achieve that? I am a newbie, so can you please tell me the simplest way without importing? Thanks in advance.

I looked up lots of posts from here but didn’t find anything similar. I tried taking a list input by something like list_a = list(input("Enter: ")) but it resulted in the problem I mentioned already.



You need to sign in to view this answers

Exit mobile version