how do i delete more than one character on python?

You can use sub

import re


def help_mmtf():
    while True:

        user_input = input("Filename?")
        text_input = str(user_input)

        if (text_input != ""):
            word = text_input



            splice_input = re.sub("\{.*?\}", "", word)
            print(f'"{splice_input}"')

        else:


         break

Time complexity: O(2^m + n).

or you can use the for loop

def help_mmtf():
    while True:

        user_input = input("Filename?")
        text_input = str(user_input)

        if (text_input != ""):
            splice_input = ''

            paren = 0
            for ch in text_input:


                if ch == '{':
                    paren = paren + 1
                    splice_input = splice_input

              
        
                elif (ch == '}') and paren:
                    splice_input = splice_input
                    paren = paren - 1

                elif not paren:
                    splice_input += ch

            print(splice_input)

        else:


         break

Time complexity: O(n).

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top