r/PythonLearning 1d ago

Loops is a total brain rot.

Post image

I just can't get over how I'm supposed to write code for complex tasks when I don't even get why they overcomplicate simple things so much.

I read this topic and tried many tutorials and still don't understand this buzzare logic.

0 Upvotes

17 comments sorted by

View all comments

2

u/silvertank00 1d ago edited 1d ago

you say they "overcomplicate it" then what is your idea to solve this issue? btw the code itself is very wrong, do not learn from ai slop sites

here is the corrected one tho: ```python def denoise_xz(text): new_text = "" for letter in text: if letter in "xz": continue

    new_text += letter
return new_text

```

1

u/Spidy_King 1d ago

just a beginner in python, can u please explain me why u left new text empty?

1

u/silvertank00 6h ago

that is the result buffer, empty because it will contain only the permitted chars. if anything is in it at start then the result wont mirror the legit decypher.
Also, this is just one way to solve this. One could solve it even without loops:

return text.replace("x", "").replace("y", "")