r/badcode • • Apr 24 '21

python very efficient and scalable code

Post image
1.0k Upvotes

110 comments sorted by

View all comments

-51

u/NetherFX Apr 24 '21

Still pretty readable, and I can't quickly think of an improvement

2

u/SuperPotterCrazy01 Apr 24 '21

Wouldn't a set give the same effect?

6

u/Schlagbaum3000 Apr 24 '21

No, each function removes the element if it exists in the list, a set would just do nothing (keep it in the set). This is probably to toggle the selection of tags.

6

u/66bananasandagrape Apr 24 '21

Why not do "if it's in the set, remove it, otherwise add it"?

If you're feeling slick you might even write it as

my_set = set()
...
my_set ^= {"thing_to_toggle"}

Maybe this person wanted to rely on the order of the tags though, in which case using a list is more understandable.

2

u/SuperPotterCrazy01 Apr 24 '21

Ah sorry I didn't see that part