0

I have one issue while iterating the regex.

def wordsaraemovalFromPpt():
        pptxListremove = []
        for i in pptxFileList:
            ppt = Presentation(i)
            for j in userInputForRemove: #["Car","car","caR","Cars","ZZCarSzz"]
                for slide in ppt.slides:
                    for shape in slide.shapes:
                        if shape.has_text_frame:
                            pattern = re.findall(j, shape.text, re.IGNORECASE)
                            pptxListremove.extend(pattern)
                print(pptxListremove)
            ppt.save(i)
    wordsaraemovalFromPpt()

Suppose in ppt file i have word like "Car","car","caR","Cars","ZZCarSzz".

but i want only "Car","car","caR",

i dont want "Cars","ZZCarSzz"

3 Answers 3

2

you don't need regex for that. Just use the filter built-in function

your_list = ["Car","car","caR","Cars","ZZCarSzz"]
your_list = list(filter(lambda w: w.lower() == "car", your_list))
print(your_list)

and output

['Car', 'car', 'caR']
Sign up to request clarification or add additional context in comments.

Comments

1

You can also use a list comprehension for this:

pptxListremove = [x for x in userInputForRemove if x.lower() == "car"]

Comments

0
your_list = ["Car","car","caR","Cars","ZZCarSzz"]
your_list = list(filter(lambda w: w.lower() == "car", your_list))
print(your_list)

It worked for me. Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.