scripting - creating an iterator in Python from a dictionary in memory-efficient way -
I'm running a very large tab-delimited file (containing millions of rows) and depending on it The values of some fields in the file I am pairing lines, eg
mydict = defaultdict () for the row in myfile: # Place the group of all rows in the same field in the list in mydict [line.field]. Append (line) Since "MIDDICT" becomes very big, I want to make it in an iterator so I do not have to capture it all in memory instead of making a dictionary I How can I make it, I make an Iterator, by which I can loop and all these lists get the same area value?
Thank you.
"millions of lines" are not too big, unless the lines are long if the lines are long You can save some storage by storing only the files in the file ( .tell () / .seek () ). If the file is sorted by line.field ; you can use. SQLX <<> Group BY can help with files of the average size (like using sqlite ). In fact for larger files you can use.
Comments
Post a Comment