2011-12-13 93 views
0

我有一個簡單的代碼:如何簡化此代碼?

results = mongo.group(                    
     key = [ 'test','id' ], 
     .... 
    ) 
    temp_hash = {} 
    for result in results: 
     if temp_hash.has_key(result['test']): 
      temp_hash[result['test']] = int(temp_hash[result['test']]) + 1 
     else: 
      temp_hash[result['test']] = 1 

如何使用MongoDB的唯一邏輯簡化這個代碼?

回答