May-28-2018, 07:30 AM
i have a set which contains many words/strings. i want to delete one. but
setname.remove(theword)
will raise KeyError if it is not already in there. in my case, it may not. so i can do if word in setname: setname.remove(theword)
. does that slow it down much? this is going to be in a heavy execution part of my code? any fast way to do this? the number of different words to be deleted is just 4. would it be better to keep the 4 words as 4 sets (each containing 1 word) and doing setname -= thewordset
.