just learned about dict.setdefault tonight, after I was going to subclass dict to add the desired functionality, and stumbled across it. it saved me 26 seconds of runtime by changing: with open(filename) as infile: to infile = OPEN_FILES.setdefault(filename, open(filename, 'rb')) in a subroutine that gets called a few thousand times. from 13m17s to 12m51s.
Back to blog or home page
last updated 2019-01-05 01:28:25. served from tektonic.jcomeau.com