Economist_Ayahuasca
Economist_Ayahuasca

Reputation: 1642

loop within a loop Python

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

Answers (2)

python_Skylake
python_Skylake

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

Raunak Kukreja
Raunak Kukreja

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

Related Questions