Improve memory efficiency

This commit uses generator expressions and dict's iteritems method to 
improve memory efficiency of DDB.