Thank you for all the answers! My problem is solved even better than I expected!
@Peter: Yes, the garbage collector was causing the slowdown. Switching it off sped the program up; each iteration was taking the same amount of time. I ran collection manually every 10 iterations to control memory usage. @Bosko: Right, this example code had a bug, appending to the dictionary was meant to be one nesting level up. @Nick: Using a tuple cache is a great advice! My real program's tuples are even better to cache, as there are roughly about 10 different tuples that are used as values. Using a tuple cache reduced the memory consumption by about 3-4 times (I'm telling that by looking at the gkrellm display). Thanks! Maciej -- http://mail.python.org/mailman/listinfo/python-list