[Python] Creating a character grid from a table; output is inverted

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I was given a problem that takes in a table of information (grid coordinates and characters) and asked to place them into a table to make a message.

    I've spent time working on some Python to work it out but my answer is coming out upside down and I can't figure out why.

    import requests
    from bs4 import BeautifulSoup

    webpage_response = requests.get('https://docs.google.com/document/d/e/2PACX-1vRMx5YQlZNa3ra8dYYxmv-QIQ3YJe8tbI3kqcuC7lQiZm-CSEznKfN_HYNSpoXcZIV3Y_O3YoUB1ecq/pub')
    webpage = webpage_response.content
    #print(webpage)

    soup = BeautifulSoup(webpage, 'html.parser')
    table = soup.find('table')
    #print(doc_table)

    rows = table.find_all('tr')

    data = []
    for row in rows[1:]:
    cells = row.find_all('td')
    character = cells[1].text.strip()
    x = cells[0].text.strip()
    y = cells[2].text.strip()
    data.append((character,x,y))

    #print(data)

    max_x = max(x for _,x,_ in data)
    max_y = max(y for _, _,y in data)
    #print(max_x)
    #print(max_y)

    grid = [[' ' for _ in range(int(max_x) + 1)] for _ in range(int(max_y) + 1)]

    for character, x, y in data:
    grid[int(y)][int(x)] = character

    for row in grid:
    print(''.join(row))


    This is my code. It should print out a grid of characters that look like a capital F but its upside down. I think the problem arises when I populate the grid but I'm not sure how to fix it.

    Continue reading...

Compartilhe esta Página