坐标打印颠倒

问题描述 投票:0回答:1

我一直在尝试对数据注释技术进行入门评估,特别是提示您需要访问网站,以非数字/非数字的 x 和 y 坐标的形式从 google 文档中提取数据-字母符号,然后将它们打印出来以形成密码。这是我打印时代码的样子:

█▀▀▀
█▀▀ 
█ 

这是我运行它时的样子:

█
█▀▀
█▀▀▀

知道为什么我要把这个颠倒过来吗?以及如何修复它的提示?非常感谢。

这是我的代码:

import re
import requests
from bs4 import BeautifulSoup

# Get text from website
r = requests.get("https://docs.google.com/document/d/e/2PACX-1vRMx5YQlZNa3ra8dYYxmv-QIQ3YJe8tbI3kqcuC7lQiZm-CSEznKfN_HYNSpoXcZIV3Y_O3YoUB1ecq/pub")
soup = BeautifulSoup(r.text, "html.parser")
code = soup.text.split("coordinate")

# create dictionary with key as (x, y) coordinate and value as the symbol found
coords = dict()
x = re.findall("[0-9]+\D[0-9]", code[2])

for a in x:
    if a[1] not in "0123456789":
        coords[(int(a[0]), int(a[2]))] = a[1]
    else: 
        coords[(int(a[0:2]), int(a[3]))] = a[2]

#create and plot the on the grid.         
HEIGHT = 10
WIDTH = 100

for y in range(HEIGHT):         
    for x in range(WIDTH):             
        try:
            print(coords[(x, y)], end='')  
        except:
            continue
    try:
        print()
    except:
        continue
python python-3.x dictionary coordinates
1个回答
0
投票

您需要以相反的顺序打印。

for y in range(HEIGHT,-1,-1):         
    for x in range(WIDTH):             
        print(coords.get((x, y),' '), end='')  
    print()
© www.soinside.com 2019 - 2024. All rights reserved.