How to append list without the quotations appearing on numbers?

Question:

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:

enter image description here

Asked By: Hamza Asim

||

Answers:

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']

Answered By: Aidis
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.