144
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 12 '20
Image Transcription: Code
[The last four lines in the following snippet of code are cut off in the screenshot:]
# Adds a reaction if a message contains all letters of the alphabet
if 'a' in message.content.lower():
if 'b' in message.content.lower():
if 'c' in message.content.lower():
if 'd' in message.content.lower():
if 'e' in message.content.lower():
if 'f' in message.content.lower():
if 'g' in message.content.lower():
if 'h' in message.content.lower():
if 'i' in message.content.lower():
if 'j' in message.content.lower():
if 'k' in message.content.lower():
if 'l' in message.content.lower():
if 'm' in message.content.lower():
if 'n' in message.content.lower():
if 'o' in message.content.lower():
if 'p' in message.content.lower():
if 'q' in message.content.lo
f 'r' in message.co
if 's' in me
if 'I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
30
23
7
u/--B_L_A_N_K-- if (true == true) {return true;} else {return true;} Sep 13 '20 edited Jul 01 '23
This comment has been removed in protest of Reddit's API changes. You can view a copy of it here.
4
3
u/fuj1n sadistic Sep 13 '20
Have platinum mate, that was a lot of effort you put in there.
2
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 13 '20
Oh, wow! Thank you so much! :D
2
108
u/uttamo Sep 12 '20
from string import ascii_lowercase
if set(ascii_lowercase) <= set(message.content.lower()):
pass6
u/earlobe7 Sep 13 '20
TIL python less than/greater than operators on sets test for subsets/supersets. Cool
47
u/earlobe7 Sep 12 '20
shitfuck = all(c in message for c in [ chr(97+i) for i in range(26) ])
20
u/glebbash Sep 12 '20
but it was message.content.lower()
46
u/earlobe7 Sep 12 '20
Oof you right, I didn't follow specs...i guess im in the right sub.
Not even gonna correct it out of solidarity.9
1
u/0x564A00 Sep 13 '20
And what's missing in both this and the original code is to apply unicode normalisation NFC or something similar to make sure accented letters don't match even when decomposed.
6
10
Sep 12 '20
why dont you try to make it all like x="alphabet" if x bla bla bla im not good at texts
32
u/NeveryEvermore Sep 12 '20
You can already compare the sets in python. so you can just do
set_a = set("The quick brown fox jumps over the lazy dog")
set_b = set("abcdefghijklmnopqrstuvwxyz")
set_b.issubset(set_a)
10
9
Sep 13 '20
Oh God this makes me uncomfortable. My teeth itch, my skin is retracting toward my spine, and I'm smelling burnt toast.
1
3
4
2
u/maxduskwalker Sep 13 '20
Wouldn't it be better approach to go for regex here ? It's always a good idea to avoid nested loops or conditions!
1
u/lucdewit Sep 13 '20
The most cursed thing about this, is the indentation on the first if statement
1
u/oberguga Sep 13 '20
Also inefficient but doing the exactly the same as code above.
charlist can be ('a','b','c',...) of a string
def sillyfunc(message,charlist) For char in charlist: If char in message.content.lower() return True return False
1
Sep 13 '20
won't this just return True if the message has an 'a' in it?
I think you mean:
def sillyfunc(message,charlist):
for char in charlist:
if not char in message:
return False
return True
1
1
u/Kit_Saels Sep 12 '20
What is on the picture?
3
u/TSM- Sep 13 '20
Someone had transcribed it 2 hours before your comment
edit: The link is https://www.reddit.com/r/badcode/comments/irjn6p/thanks_i_hate_you/g4zc25p
118
u/Kazumara Sep 12 '20
This is python right?
Don't ask how I know but if you are using CPython then any function that is nested beyond 20 levels of depth will throw a syntax error.
Edit: Although now that I think about I only know that's the limit for loops, not sure whether conditionals count towards the same