Drawing Levels using W(string) in pygame [closed]

I want to make a level using string

The:

level = []

inside the level you put W’s in it

How do i draw and display the data inside?

Answer

I have seen people do that to make tile maps. Basically, you make a list of list. The outermost list represents the entire level and each inner lists represent each row of tiles in that level. What is inside that inner list determines what tiles make up each row. How you iterate through it and display the tiles is up to you but here is one way of doing it.

import sys
import pygame

pygame.init()
screen = pygame.display.set_mode((600, 600))

level = [["w", "w", "w", "w", "w", "w"],
         ["w", "r", "g", "w", "b", "w"],
         ["w", "w", "r", "g", "b", "w"],
         ["w", "g", "b", "b", "w", "w"],
         ["w", "b", "w", "g", "g", "w"],
         ["w", "w", "w", "w", "w", "w"]]

wsize = 100

while True:
    for event in pygame.event.get():
        keys = pygame.key.get_pressed()
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()  

    screen.fill((255, 255, 255))

    for y, row in enumerate(level):
        for x, tileType in enumerate(row):
            if tileType == "w":
                pygame.draw.rect(screen, (0, 0 ,0), (x * wsize, y * wsize, wsize, wsize))
            if tileType == "g":
                pygame.draw.rect(screen, (0, 255 ,0), (x * wsize, y * wsize, wsize, wsize))
            if tileType == "b":
                pygame.draw.rect(screen, (0, 0 ,255), (x * wsize, y * wsize, wsize, wsize))
            if tileType == "r":
                pygame.draw.rect(screen, (255, 0 ,0 ), (x * wsize, y * wsize, wsize, wsize))
            

    pygame.display.update()