I have a list such as this (this is pulled from some html texts using bs4):
test = ['Raji GlovesSixSixOneRegular price\n$29.99\nSale price$9.95\n\n Save 67%\n \nBUY 2 GET 1 FREE',
'Comp Vortex GlovesSixSixOneRegular price\n$29.99\nSale price$9.95\n\n Save 67%\n \nBUY 2 GET 1 FREE',
"Shasta 3/4 Cycling Tights - Women'sSpecializedRegular price\n$70.00\nSale price$14.95\n\n Save 79%",]
len(test) # 3
I want to loop through each line in the list (list of 3), and extract the 0,2nd and 4th indexed item for each line. so that the output looks like this:
This nested list contains all the items that I want to see.
out = [['Raji GlovesSixSixOneRegular price',
'Sale price$9.95',
' Save 67%'],['Comp Vortex GlovesSixSixOneRegular price',
'Sale price$9.95',
' Save 67%'],["Shasta 3/4 Cycling Tights - Women'sSpecializedRegular price",
'Sale price$14.95',
' Save 79%']]
I know that I can extract the items from the first line like this:
item1 = test[0]
item1 = item1.split(sep = '\n')
item1
indices = [0,2,4]
values =[]
for i in indices:
print(item1[i])
values.append(item1[i])
values
['Raji GlovesSixSixOneRegular price',
'Sale price$9.95',
' Save 67%']
I am new to python, and I struggling to pull out these items from each line, and append them back in a nested list (see out above).
Any idea's for how to achieve this?