MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/mxlgzm/very_efficient_and_scalable_code/gvpwp0y/?context=3
r/badcode • u/Conqu3red • Apr 24 '21
110 comments sorted by
View all comments
-51
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 asmy_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
2
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 asmy_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
6
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 asmy_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
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.
Ah sorry I didn't see that part
-51
u/NetherFX Apr 24 '21
Still pretty readable, and I can't quickly think of an improvement