Convert tuple to list and back


I"m currently working on a map editor for a game in pygame, using tile maps. The level is built up out of blocks in the following structure (though much larger):

level1 = (

where "1" is a block that"s a wall and "0" is a block that"s empty air.

The following code is basically the one handling the change of block type:

clicked = pygame.mouse.get_pressed()
if clicked[0] == 1:
    currLevel[((mousey+cameraY)/60)][((mousex+cameraX)/60)] = 1

But since the level is stored in a tuple, I"m unable to change the values of the different blocks. How do I go about changing the different values in the level in an easy manner?

Answer rating: 332

Convert tuple to list:

>>> t = ("my", "name", "is", "mr", "tuple")
>>> t
("my", "name", "is", "mr", "tuple")
>>> list(t)
["my", "name", "is", "mr", "tuple"]

Convert list to tuple:

>>> l = ["my", "name", "is", "mr", "list"]
>>> l
["my", "name", "is", "mr", "list"]
>>> tuple(l)
("my", "name", "is", "mr", "list")

Get Solution for free from DataCamp guru