Given a string word
, I'm trying to estimate the Big-O time complexity of the following function.
def wildcards(word: str) -> Iterator[str]:
for j in range(len(word)):
yield f"{word[:j]}_{word[j + 1:]}"
I've read Is the time-complexity of iterative string append actually O(n^2), or O(n)? and Time complexity of string concatenation in Python, both of which are concerned with repeated string concatenation, which isn't happening here.
This answer says slicing is linear in size of the slice, so, two slices takes O(n)
time in total. But what about the f-string?
Overall, it looks to me that wildcards
is O(n2), is that right?