Python表比较

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

是否有任何方法可以与同一张for循环同时打印的打印表进行比较?可以将petl用于此类逻辑吗?。

我的确切意思

loop = 2
up = 3
down = 4
listvar = [5, 6, 5, 8, 9, 7, 8, 5, 6]

docuvar = docx.Document()

for x in range(loop):
    tablevar = docuvar.add_table(rows=5, cols=5)
    for cell in (tablevar.rows[1].cells):
        for x in range(down):
            randomvar = random.choices(listvar)
        cell.text = str(randomvar)

我们有什么方法可以实时比较和控制每个单元格中的整数打印或字符串打印?

python python-3.x python-docx
1个回答
0
投票

仍然不确定,您到底想比较什么,但是这里有一个示例,您可以比较值:

loop = 2
up = 3
down = 4
listvar = [5, 6, 5, 8, 9, 7, 8, 5, 6]

docuvar = docx.Document()

completeList = []

for x in range(loop):
    anotherList = []
    tablevar = docuvar.add_table(rows=5, cols=5)
    for cell in (tablevar.rows[1].cells):
        #** This loop her makes no sense, except:**
        for x in range(down):
            randomvar = random.choices(listvar)
        #** you intend cell.text**
            cell.text = str(randomvar)

            #eg comparing:
            if completeList:
                for list in completeList:
                    if list[x] == str(randomvar):
                        #control smth...
                        pass

            anotherList.append(str(randomvar))
    completeList.append(anotherList)
© www.soinside.com 2019 - 2024. All rights reserved.