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 append list without the quotations appearing on numbers?

I am trying to create a maze using list of lists, where each line of a maze is a separate element of a list. This list has numbers 0 or 1 which determine the wall/path in the maze as well as the start ("S") and end ("E").
But when I append each individual number to the list it’s all appearing in quotation marks. The letters in quotations is fine but I want the numbers to be added without the quotations.
Is there a way to do this?

This is my code for appending to the list:

if maze != "invalid":
        row = maze.split(",")
        for line in row:
          col = []
          for element in range(0, len(line)):
            col.append(line[element])

      mazelist.append(col)
    transformed_maze_validation.append(mazelist)

This is the output I get:

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 image description here

>Solution :

Here is a snippet that shows how you can make sure that everything that can be converted to int is converted.

items = ['1','2','S','E']
results = []

for item in items:
    try:
        item = int(item)
    except ValueError:
        pass
    results.append(item)

Result in [1, 2, 'S', 'E']

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