I’m learning python — and I just did this:
EXCLUSIONLIST = [ '10.0.0.1', '10.0.0.2', '10.0.0.3', '10.0.0.4', '10.0.0.5' ] # Clean up the generated lists, as well as the exclusions: # LIST1, LIST2 should not contain any extra crap now. def listcleaner(): for i in TOREMOVE: logging.info("removing " + str(i)) try: LIST1.remove(i) except: pass try: LIST2.remove(i) except: pass for i in EXCLUSIONLIST: logging.info("removing " + str(i)) try: LIST1.remove(i) except: pass try: LIST2.remove(i) except: pass
So I know there’s a better way to do it, but not sure how to search it. I’ll update this when I’ve golfed with it a couple times. Don’t lecture me about
pass. I get the badliness, it’s just in the case of where and why I’m running this, I truly don’t need the error message (famous last words).
LIST1 = [ 5,10,15,20,25 ] LIST2 = [ 3,7,11,13,19 ] TOREMOVE = [ 3,15,19,20 ] EXLUSIONS = [ 5,7 ] for i in EXLUSIONS: TOREMOVE.append(i) for x in TOREMOVE: print(x) if x in LIST1: LIST1.remove(x) if x in LIST2: LIST2.remove(x)
I wish I could say right after I posted I went and cleaned this up to what you see here, but that is not the case. I’m not sure where my head was with the
TRY statements, they were very unnecessary. Either way they are gone now! Much cleaner, and this has the advantage of combining the
EXCLUSIONS lists so if I want to dump a report/log I can do so more easily.
I’m sure there is a way to get this down even further, but this is the point at which my curiosity is satisfied.