将列表中的值与另一个列表进行比较并遍历列表并将其存储在列表中

时间:2021-07-18 10:44:29

标签: python

我正在运行一个代码来比较元组和列表中的值 int 和 str,这里的问题是它不能同时使用 int 和 string,

def remove_img_on_pdf(idoc, page):
    value = idoc.getPageImageList(page)
    print(value)
    b = ["X0","X1","X2","X3","X4","X5","X6","X7","X8","X9","X10","X11","X12","X13","X14","X15","X16"]
    length = len(b)
    i = 0
    while i < length:
        x = b[i]
        img_list = ([item for item in value if 13 & "X0" in item])
        i = i + 1
    print(img_list)
    con_list = idoc[page].get_contents()

它给了我这个错误

  File "watermark.py", line 14, in remove_img_on_pdf
    img_list = ([item for item in value if 13 & "X0" in item])
  File "watermark.py", line 14, in <listcomp>
    img_list = ([item for item in value if 13 & "X0" in item])
TypeError: unsupported operand type(s) for &: 'int' and 'str'

我需要取列表 b 中的单个元素并比较值元组中的元素,

value = [(13, 0, 120, 74, 8, 'DeviceRGB', '', 'Image1', 'DCTDecode'), (303, 304, 318, 299, 8, 'DeviceRGB', '', 'X16', 'FlateDecode')]
[(13, 0, 120, 74, 8, 'DeviceRGB', '', 'Image1', 'DCTDecode')]  #compared value "13" printed.

我需要同时打印出 13"X16" 值,就像这样

[(13, 0, 120, 74, 8, 'DeviceRGB', '', 'Image1', 'DCTDecode'), (303, 304, 318, 299, 8, 'DeviceRGB', '', 'X16', 'FlateDecode')]
[(13, 0, 120, 74, 8, 'DeviceRGB', '', 'Image1', 'DCTDecode'), (303, 304, 318, 299, 8, 'DeviceRGB', '', 'X16', 'FlateDecode')]

请帮我解决这个问题,谢谢

0 个答案:

没有答案
相关问题