r/badcode • • Apr 24 '21

python very efficient and scalable code

Post image
1.0k Upvotes

110 comments sorted by

View all comments

Show parent comments

96

u/RoboticPlayer Apr 24 '21

Just pass it as a parameter

def chooseTag(tag):
    if tag in selectedTags:
        selectedTags.remove(tag)
    else:
        selectedTags.append(tag)
    print(selectedTags)

6

u/lizard450 Apr 24 '21

Use a hashtable would be an improvement... Or an enum bit array.

5

u/RoboticPlayer Apr 24 '21

True, but what I did is simple and it's what I thought of off the top of my head :)

2

u/lizard450 Apr 24 '21

That's how you get to good code. A series of simple improvements.