pythondictionarydefaultdict

How to print defaultdict variable without its type?


In the following code:

from collections import defaultdict

confusion_proba_dict = defaultdict(float)

for i in xrange(10):
    confusion_proba_dict[i] = i + 10

print confusion_proba_dict

Output is:

defaultdict(<type 'float'>, {0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17, 8: 18, 9: 19})

But, I need output to be:

{0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17, 8: 18, 9: 19}

How can I do it?


Solution

  • just transform it to a regular dict

    print( dict(confusion_proba_dict) )
    

    but if you are going to use like that, just use a regular dict as you don't use any of the advantages of defaultdict