
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Optimize Python Dictionary Memory Usage
There are some cases where you can simply avoid using dictionaries in python. For example, if you're creating a dict of continuous integers to some values, consider using a list instead.
If you're creating string-based keys, you might be better off using a Trie data structure(http://en.m.wikipedia.org/wiki/Trie).
There are other cases where you can replace the use of dicts by some other less memory intensive data structure.
But you need to understand that at some places, you have to use a dict as it helps in optimization. The python dict is a relatively straightforward implementation of a hash table. This is how hash tables are implemented in most languages like Java, C++, etc.
Advertisements