'I have two lists with somewhat similar data that I want to compare and pull out the most similar from the parent list [duplicate]
I'm sure this is already out there somewhere but I cannot find it. So I have two list:
sheet_names = ['T307710_TOOLS', 'T307710_CSYS'] #This is pulled in from wb.get_sheet_names()
look_for = ['tools', 'Tools', 'TOOLS', 'setup', 'Setup', 'SETUP'] #these are the terms I am looking for in the sheet names
I want to compare the two and then pull the 'T307710_TOOLS' name and position and then store that in a variable tool_sheet.
This is my attempt at it, I am not sure how to compare the two list in the nested for-loop:
#multiple sheet names, only 1 will specify either TOOLS or SETUP
sheet_names = ['T307710_TOOLS', 'T307710_CSYS'] #wb.get_sheet_names() in my code
#the sheet name I am looking for can be anything from T3771_TOOLS to setupsheet
look_for = ['tools', 'Tools', 'TOOLS', 'setup', 'Setup', 'SETUP']
#me attempting to iterate through the sheet names
for i in sheet_names:
for j in look_for:
if j is in i:
tool_sheet = i
Solution 1:[1]
for i in sheet_names:
for j in look_for:
if j in i:
tool_sheet = i
Difference was "is in" vs "in" in for-loop
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | smichael_44 |
