Empty a dictionary subclass in python

I'm using a django module that uses a class that inherits from dict. Let's call it ExtendedDict. Suppose I'm given an instance, e_d, of the ExtendedDict class and I want to clear it out. What's the most pythonic way to empty it?

This feels clunky:

for key in e_d: e_d.pop(key)

Is there a better solution?

Answers


Since your class inherits from dict, its instances should have a clear() method:

e_d.clear()

Need Your Help

Android NDK future extended support for C++

android irc android-ndk

Is there any info about the future of extending the safe C++ header list in the NDK (or maybe some hints to what might be safe to use) ? Or how soon we can expect the next NDK update? Also will the...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.