在Python中拆分元组

时间:2017-01-04 08:04:12

标签: python python-2.7

我试图编写一些Python来获取两个元组并将其拆分为单独的单词,稍后使用这些单词进行比较。但拆分方法不起作用。任何人都可以帮助我是python的新手。(代码和错误被给出)

vb2010

error given in the image

2 个答案:

答案 0 :(得分:2)

为什么你首先创建一个元组?如果您尝试在电子表格单元格中拆分值,请使用此

for i in range(3, 8):

    cell_1 = assign_sheet.cell(row=i, column=2).value
    cell_2 =assign_sheet.cell(row=i, column=3).value
    s1= cell_1.split(" ")
    s2= cell_2.split(" ")
    temp=[]
    for w in s1:
        if w in s2:
            temp.append(w)
            print temp

答案 1 :(得分:0)

在3和8之间的每一行打印第2栏和第3栏中的单词

for i in range(3, 8):
    # get cell 1 and 2
    cell_1 = assign_sheet.cell(row=i, column=2).value
    cell_2 = assign_sheet.cell(row=i, column=3).value

    # split on spaces (gives a list per cell)
    s1 = cell_1.split(" ")
    s2 = cell_2.split(" ")

    # combine lists and print them
    temp = s1 + s2
    print temp
相关问题