Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlying datastructure of list, tuple, dict [closed]

I would like to get some understanding on how the data types in python - list, tuple, dict and set - are implemented

How are they implemented, importantly the data structure used. Any place/ url to precisely get this understanding?

like image 941
Raghav Avatar asked Feb 19 '14 07:02

Raghav


1 Answers

The best place to look is the CPython implementation source code:

  • dict - Hash map targeting fast resolution of keys
  • list - Looks like an array of PyObjects
  • tuple - Same as list but with optimisations that a tuple can allow (fixed size, objects)
  • set - Hash map with optimisations for cache locality

The source code is heavily commented and well written C. This would be the best place to understand the data structures used in detail.

like image 162
Matt Clarkson Avatar answered Sep 27 '22 15:09

Matt Clarkson