can you format an enumerated list?


I am trying to use .replace and .lstrip on an enumerated list. is there a workaround since it doesnt seem to work on tuples?

for file in onlyfiles:#for file in current directory
with as doc: #open the file
    text="" #create a blank text variable
    for page in doc: # for each page in the file
        text += page.get_text() # add the text from the page to the blank text block
        text_1 = re.split('.(?![0-9])', text)

    words = ['increase','growth']
    print(f'File name: {file}')
    for word in words:
        print(f'Keyword: {word.title()}')
        sentences = [sentence for sentence in text_1 if word.lower() in sentence.lower()]
        for sentence in enumerate(sentences, start=1):

Example of code and output

I would like to be able to remove newline characters. When i added to the print(sentence) line, it told me tuples have no object replace.

Asked By: nji1997



The enumerate(iterable, start) function will return a sequence of tuples. If we loop through that sequence normally like this, we get a tuple on each iteration:

for t in enumerate(iterable):
print(t) #t is a tuple

But the syntax we showed above unpacks that tuple on each iteration, so:

for a, b in enumerate(iterable):
print(a) #first value in the tuple (the count)
print(b) #second value in the tuple (the item in the original iterable)
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.