The curve ball is the case insensitivity otherwise it's a straightforward set operation.
I wonder if it's possible to sub-class set and make the item comparision case insensitive. Anybody knows how to do that? Tim Chase wrote: > > Yeah, I ended up doing a similar kind of loop. That is pretty messy. > > > > Is there any other way? > > I've already provided 2 (or 3 depending on how one counts) > solutions, each of which solve an interpretation of your original > problem, neither of which involve more than 3 lines of fairly > clean code. Perhaps a little more context regarding what you > *want* to do would help. However, I suspect that answer is > "there is no *cleaner* way to do it". > > Unless you're modifying an existing list that is referenced > elsewhere, the reassignment (l = [x for x in l ...]) solution > should work just fine. Thus, unless you have a situation akin to: > > g = l > l = [x for x in l if x.lower() not in s] > assert(thing_from_s not in g) > > then just reassign "l". If not, use the loop. It's that easy > and clean. Don't try to opaquify it by collapsing it further. > Perhaps, if your loop is messy, use my clean loop suggestion. > > -tkc -- http://mail.python.org/mailman/listinfo/python-list