I have a dict. There are about 10,000 key:value pairs in this dict.
I want to write these pairs(just as strings) 1-100 to a file, then pairs 101-200 to a second file, then 201-300 to a third file etc.
How would one do that in python?
I have a dict. There are about 10,000 key:value pairs in this dict.
I want to write these pairs(just as strings) 1-100 to a file, then pairs 101-200 to a second file, then 201-300 to a third file etc.
How would one do that in python?
The iteration methods is based on Iterating over dictionaries using 'for' loops
c = 0
f = open('%d.txt'%(c),'w')
for key, value in d.iteritems():
print>>f,"%s:%s"%(str(key),str(value))
c += 1
if c % 100 == 0:
f.close()
f = open('%d.txt'%(c/100),'w')
f.close()