第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

以字符串網(wǎng)格格式打印集合列表

以字符串網(wǎng)格格式打印集合列表

慕妹3242003 2022-10-18 19:45:08
這是我得到的txt文件:......B..............A.....................D...........C............E............從這個(gè)文本中,我制作了以下元素,用于從 txtfile 中的每個(gè)點(diǎn)獲取壁櫥字母表。location_alpha ={(2, 3): 'A', (0, 6): 'B', (6, 1): 'C', (4, 7): 'D', (7, 5): 'E'}location_allpoint = [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (3, 0), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (5, 0), (5, 1), (5, 2), (5, 3), (5, 4), (5, 5), (5, 6), (5, 7), (5, 8), (6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (6, 5), (6, 6), (6, 7), (6, 8), (7, 0), (7, 1), (7, 2), (7, 3), (7, 4), (7, 5), (7, 6), (7, 7), (7, 8), (8, 0), (8, 1), (8, 2), (8, 3), (8, 4), (8, 5), (8, 6), (8, 7), (8, 8)]我嘗試做的是將txt文件中的所有點(diǎn)更改為最接近的字母并以字符串格式打?。?nbsp;  aaaabbBbb   aaaaabbbb   aaaAaabdd   aaaaaaddd   ccaaaddDd   cccceeddd   cCcceeedd   ccceeEeee   ccceeeeee為此,我得到的是 txt.file 中每個(gè)項(xiàng)目的最近點(diǎn):我試圖做的是首先將列表中每個(gè)元素的小寫(xiě)打印為 row*col 字符串網(wǎng)格格式,例如上面的示例,然后更改原始字母表的索引為大寫(xiě)。 for i in nearest_alphabet_from_point:       if len(i) ==2: # one that comes first lexicographically must be used in case ex){'A', 'C'} ==> 'A'nearest_alphabet_from_point =[{'A'}, {'A'}, {'A'}, {'A'}, {'B'}, {'B'}, {'B'}, {'B'}, {'B'}, {'A'}, {'A'}, {'A'}, {'A'}, {'A'}, {'B'}, {'B'}, {'B'}, {'B'}, {'A'}, {'A'}, {'A'}, {'A'}, {'A'}, {'A'}, {'B'}, {'D'}, {'D'}, {'A', 'C'}, {'A'}, {'A'}, {'A'}, {'A'}, {'D', 'A'}, {'D'}, {'D'}, {'D'}, {'C'}, {'C'}, {'A', 'C'}, {'A'}, {'A'}, {'D'}, {'D'}, {'D'}, {'D'}, {'C'}, {'C'}, {'C'}, {'C'}, {'E'}, {'E'}, {'D'}, {'D'}, {'D'}, {'C'}, {'C'}, {'C'}, {'C'}, {'E'}, {'E'}, {'E'}, {'D'}, {'D'}, {'C'}, {'C'}, {'C'}, {'E'}, {'E'}, {'E'}, {'E'}, {'E'}, {'E'}, {'C'}, {'C'}, {'C'}, {'E'}, {'E'}, {'E'}, {'E'}, {'E'}, {'E'}]但我從第一步開(kāi)始就無(wú)法以字符串網(wǎng)格格式打印它。我怎樣才能做到這一點(diǎn)?
查看完整描述

1 回答

?
富國(guó)滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

如果您只想打印網(wǎng)格,為什么不做這樣的事情呢?


N = len(nearest_alphabet_from_point)

W = 9

L = N//W

ind = 0

for i in range(L):

    for j in range(W):

        temp = list(nearest_alphabet_from_point[ind])

        ind += 1

        print(temp[0],end='')

    print('')

輸出


AAAABBBBB

AAAAABBBB

AAAAAABDD

AAAAAADDD

CCAAADDDD

CCCCEEDDD

CCCCEEEDD

CCCEEEEEE

CCCEEEEEE

如果要構(gòu)造 agrid的list類型,則可以執(zhí)行以下操作:


N = len(nearest_alphabet_from_point)

W = 9

L = N//W

ind = 0

grid = []

for i in range(L):

    row = []

    for j in range(W):

        ch = list(nearest_alphabet_from_point[ind])[0]

        if (i,j) not in location_alpha:

            ch = ch.lower()

        row.append(ch)

        ind += 1

    grid.append(row)


查看完整回答
反對(duì) 回復(fù) 2022-10-18
  • 1 回答
  • 0 關(guān)注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)