Reputation: 1642
I am trying to run a loop within a loop and I am totally confused.
for i, value in enumerate(len(sections):
if i not in [17, 24]:
if (' tax ' in sections[i]
or ' Tax ' in sections[i]):
pat=re.compile("|".join([r"\b{}\b".format(m) for m in months]), re.M)
month = pat.search("\n".join(sections[i].splitlines()[0:6]))
print(month)
The problem is that I want to run the loop for all values in len(sections)
except 17 and 24. The idea is the following: for each section (article), if the word tax or tax is in it, print the month. Everything is working but the lines at the beginning, where I am trying to run the loop except the values 17 and 24.
Cheers,
Upvotes: 1
Views: 135
Reputation: 3
the syntax : for ( i,j) in enumerate(mylist)
returns at once tuple of two values . the first is the index of an element and the second one is value corresponding to this element. Think about it to rebuild your program.
Upvotes: -1
Reputation: 171
This should work:
for i, value in enumerate(sections):
if i not in [17, 24]:
if ' tax ' in sections[i] or ' Tax ' in sections[i]:
pat = re.compile("|".join([r"\b{}\b".format(m) for m in months]), re.M)
month = pat.search("\n".join(sections[i].splitlines()[0:6]))
print(month)
Upvotes: 4