I have a function strip_punctuation(text) which takes in a string of text and removes all punctuation in it using a punctuation list. I am not sure about the time complexity whether it is O(N)*N or O(N^2). I think that it works where it is O(N) for N text length, and then O(N) for length of punctuation. May someone clarify the time complexity for this code?
def strip_punctuation(text):
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
stripped = ""
for i in text:
if i not in punctuations:
stripped = stripped + i
return stripped
stripped = stripped + i) is not recommended and is consider O(N^2) in some style guide.maketrans()andtranslate()functions in the standard library (exact details depend on the Python version you're using), they can almost certainly do this job faster (if only because the loop over characters is written in C instead of Python).