How to iterate through two dicts efficiently

J jnr.gonzalez at googlemail.com
Tue Jul 19 10:20:17 EDT 2011


Hi guys,

Thank you for your suggestions.  I have managed to get my whole script to execute in under 10 seconds by changing the 'for loop' I posted above to the following:-

for opco in Cn:
	for service in Cn[opco]:
		ack = set(Cn[opco][service]['RECV']) & set(Pr['13'])
		for jarid in ack:
			Cn[opco][service].setdefault('ACK', set()).add(jarid)
		nack = set(Cn[opco][service]['RECV']) & set(Pr['14'])
		for jarid in nack:
			Cn[opco][service].setdefault('NACK', set()).add(jarid)
		retry = set(Cn[opco][service]['RECV']) & set(Pr['504'])
		for jarid in retry:
			Cn[opco][service].setdefault('RETRY', set()).add(jarid)
		retry1 = set(Cn[opco][service]['RECV']) & set(Pr['505'])
		for jarid in retry1:
			Cn[opco][service].setdefault('RETRY', set()).add(jarid)

The script is by no means complete and I will be looking at your suggestions more closely to adapt my script accordingly based on your suggestions.

But for now I am happy to have dramatically speed up the execution of my script from over 20 mins to under 10 secs!

Thanks again for your time.



More information about the Python-list mailing list