I’m trying to search a google spreadsheet for a specific word and have it return the row number of every cell containing that word. What I am aiming to do is have 2 lists that contain the rows of cells containing two different keywords, compare the two, and return the common rows.
For example:
If list one contains row 4, 6, 8, and 10 and list two contains 4, 5, 7, 10, I want to return 4 and 10.
So far, I have it so that it returns the cell location in this format (where the keyword is “cyber”): [<Cell R65C1 ‘cyber’>, <Cell R68C1 ‘cyber’>] , but I need to have it in the form of a string with just the row number so I can compare it to another list, such as [<Cell R65C3 ‘charge’>].
column1 = 1
column2 = 2
word1 = Noe
word2 = None
list1 = []
list2 = []
keywordList = ["cyber", "charge"]
if len(keywordList) >= 1:
while column1 <= 3:
word1 = sheet.findall(keywordList[0], in_column=column1)
list1.extend(word1)
column1 += 1
if len(keywordList) >= 2:
while column2 <= 3:
word2 = sheet.findall(keywordList[1], in_column=column2)
list2.extend(word2)
column2 += 1
def intersection(list1, list2):
return list(set(list1) & set(list2))
print(intersection(list1, list2))
This is what I have so far that returns it in <Cell R65C1 ‘cyber’>, <Cell R68C1 ‘cyber’> form. Any suggestions would be greatly appreciated, thank you!