I'm really confused why the person wrote it like that. I think what it does is print the message in lowercase except the part he/she's trying to find, which is in uppercase.
So "FinD This -> woRd <- in THiS TexT" -> "find this WORD in this text"
I guess it's just the tempMessage == message.lower() which is weird since it's not Pythonic.
This is the equivalent:
if text.lower() not in message.lower():
print(text.upper(), "does not appear in the message"))
else:
print(message.lower().replace(text.lower(), text.upper()))
The downside is that message.lower() is potentially called twice, so his version is actually slightly faster but in that case you can just put the lowercase version in a variable before the condition.
Yeah, this code looks like someone looked through all the string functions and didn't find contains and so assumed it didn't have it for some reason but didn't realize you just use in for that.
This code was old code from a friend of mine from when he was just starting out coding. You often see very creative solutions to problems that don’t exist. I remember trying to simulate goto statements in Python cos my first language was BASIC for some reason (from a book)
Not only the false=False part is bad but the comparison in the if else statement also seems to be bad, because it will never evaluate to True, am I wrong?
96
u/andmagdo Dec 18 '21
Too used to other languages, must use lowercase booleans is what this looks like
37
u/[deleted] Dec 18 '21
Could you just use the following?
I know the point was line 133, just curious :)
36
u/[deleted] Dec 18 '21
I hate everything about this snippet
16
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Dec 18 '21
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
6
u/swguy61 Dec 18 '21
Could be worse, as in false=True 🤣
6
u/CaitaXD Dec 18 '21
Light mode, so its already bad at line 0
4
u/FantasticAbroad7230 Dec 18 '21
Not only the false=False part is bad but the comparison in the if else statement also seems to be bad, because it will never evaluate to True, am I wrong?
1
u/il-est-la Dec 18 '21
So is it true or false??
1
u/andoy Dec 18 '21
if(false === True)
1
u/sohang-3112 Dec 19 '21
Even worse is the whole
tempMessagerubbish in first if condition. That whole thing is equivalent to: