4

If the my_dict variable is global, you can't do:

my_dict = {}

that just create a new reference in the local scope.

Also, I found disgusting using the global keyword, so how can I empty a dict using its methods?

codeforester
  • 39,467
  • 16
  • 112
  • 140
Juanjo Conti
  • 28,823
  • 42
  • 111
  • 133

4 Answers4

8

Use the clear() method?

Documentation - (docs.python.org)

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Tao
  • 407
  • 2
  • 5
3

you mean like .clear() ?

pycruft
  • 66,157
  • 1
  • 20
  • 12
1
my_dict.clear()
Richard Fearn
  • 25,073
  • 7
  • 56
  • 55
1

my_dict.clear()

ngroot
  • 1,186
  • 5
  • 11