So I have two lists (it is extracted from google sheets via gspread library) One column from the google spreadsheets had all the brand names. I got this whole column and created a list called 'approved_brand'. I got another column and called it 'approved_seller'. These brands and sellers (in the grand scheme of things) is a list of approved sellers for each brand.
I have another spreadsheet where there are the list of actual sellers selling the particular brand. My objective is to see if the actual sellers for the particular brand are approved or not.
For example:
approved_brand=[1,2,3,4,5]
, approved_seller=[a,b,c,d,e]
(meaning a is approved to sell 1, b is approved for 2, c for 3, etc.)
brand=[1,7,8,9,4,5]
, seller=[a,d,f,g,g,e]
After checking, you should get two lists that returns [1,5]
and [a,e]
meaning out of all the sellers in those brands, only a was approved to sell 1 and e was approved to sell 4.
Get lists for approved brands and sellers.
approved_brand=referenceTable.col_values(1)
del approved_brand[0]
approved_seller=referenceTable.col_values(2)
del approved_seller[0]
Get all the brands and sellers from the data stored in google spreadsheets (list of actual brands and corresponding sellers)
brand=inputfile.col_values(2)
del brand[0]
seller=inputfile.col_values(4)
del seller[0]
for i in range(len(brand)):
if brand[i] in approved_brand and seller[i] in approved_seller:
approvedBrandInActual.append(brand[i])
approvedSellerInActual.append(seller[i])
This last for loop is not working as intended.
For iterating through lists simultaneously, use zip
. Go through lists and check if corresponding brand
and seller
are within the approved lists.
approved_brand=[1,2,3,4,5]
approved_seller=['a','b','c','d','e']
brand=[1,7,8,9,4,5]
seller=['a','d','f','g','g','e']
br, sr = [], []
for b, s in zip(brand, seller):
if (b, s) in zip(approved_brand, approved_seller):
br.append(b)
sr.append(s)
print(br) # [1, 5]
print(sr) # ['a', 'e']