---EDIT 2--- So I get the question Why I use dictionaries?, this question is a follow up on this one: csv file compression without using existing libraries in Python
I Need to compress a 500k csv file (19MB), and I chose to use dictionary to store the ticks in one csv file and symbs in another to be able to Decompress the values
QUESTION: How do I iterate the most optimized way? this is just an example of 4 rows, but my real file has 500 000 lines, and takes me for ever to iterate through the list.
I have 3 dictionaries:
originalDict = {
0: ['6NH8', 'F', 'A', '0', '60541567', '60541567', '78.78', '20'],
1: ['6NH8', 'F', 'A', '0', '60541569', '60541569', '78.78', '25'],
2: ['6AH8', 'F', 'B', '0', '60541765', '60541765', '90.52', '1'],
3: ['QMH8', 'F', 'B', '0', '60437395', '60437395', '950.5', '1']
}
ticks = {0: '6NH8', 1: '6AH8', 2: 'QMH8'}
symbs = {0: 'F,A', 1: 'F,B'}
I want to iterate through originalDict and change the "ticks" and then the symbs at index 1
and index 2
and then remove index 2
so, i.e.
0: ['6NH8', 'F', 'A', '0', '60541567', '60541567', '78.78', '20']
becomes:
[0, '0', '0', '60541567', '60541567', '78.78', '20']
I have currently a for loop going through values in originalDict, and inside that another for loop:
for values in originalDict.values():
for ticksKey, ticksValue in ticks.items():
if values[0] == ticksValue:
values[0] = ticksKey
#Change symbs and remove char combination
for symbsKey, symbsValue in symbs.items():
comprComb = values[1] + "," + values[2]
if comprComb == symbsValue:
values[1] = str(symbsKey)
#del values[4]
#del values[4]
del values[2]
ADDITIONAL INFO ADDED: The reason I have them as dictionary is because the 500 000 lines, some of the ticks occurs more than once, so, I give them a int which is the key in the dict, so goes for the symbs dictionary too.