I worked on some code. My usual approach is to first solve all parts of the problem by creating loops and other pieces of code that I need when I work on the problem, and then if I expect code to be reused, I go back through it and group the parts of the code, which, I think, should be grouped to create functions.
I just noticed that creating functions and calling them seems a lot more efficient than writing lines of code and removing containers as they are completed.
eg:
def someFunction(aList):
do things to aList
that create a dictionary
return aDict
seems to free up more memory at the end than
>>do things to alist
>>that create a dictionary
>>del(aList)
Is this the expected behavior?
EDIT added sample code
, PF 100 . 8 .
def getAllCIKS(filingList):
cikDICT=defaultdict(int)
for filing in filingList:
if filing.startswith('.'):
del(filing)
continue
cik=filing.split('^')[0].strip()
cikDICT[cik]+=1
del(filing)
ciklist=cikDICT.keys()
ciklist.sort()
return ciklist
allCIKS=getAllCIKS(open(r'c:\filinglist.txt').readlines())
, 400
cikDICT=defaultdict(int)
for filing in open(r'c:\filinglist.txt').readlines():
if filing.startswith('.'):
del(filing)
continue
cik=filing.split('^')[0].strip()
cikDICT[cik]+=1
del(filing)
ciklist=cikDICT.keys()
ciklist.sort()
del(cikDICT)
. , PF. , . . , , , ? , .
, , , GC , . ? Soo , [(aTuple), anInteger, [ ]]. , gc- , gc, , 0,1 2 , .
, . , , .