Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get rid of the single quotation marks in a list inside a list?

I wrote this piece of code, in which I ask the user to input numbers twice, and then it joins them together in a list, inside a list. It works…buts it’s in the wrong format.

Here’s what I did

list=[]
for i in range(2):
    userinput = input("Enter some numbers: ")
    x = userinput.split()
    list.append(x)
print(list)

The output is this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Enter some numbers: 1 2
Enter some numbers: 3 4
[['1', '2'], ['3', '4']]

…but I need it to be formatted [[1, 2], [3, 4]]
I’m very new python, and I feel like Ive exhausted all my options, I couldnt find anything online that works (tried the join, replace etc.) , unless its impossible with my code, please help

>Solution :

Use x = [int(i) for i in userinput.split()]; you have to convert the input strings to integers.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading