Search for the Fundamental Collection

Shantanu Sen
1 min readOct 20, 2019

Python offers four standard collections, which can be used as native data types.

  1. List
  2. Dict
  3. Set
  4. Tuple

Question is: Which one of them is the most fundamental one, using which other types can be built?

Let us first take a look at the similarities between them. Represented within curly braces, dict and set look similar. A little deeper analysis will show that set is a special case of dict with no values for keys.

Dict: {‘A’:1, ‘B’:2, ‘C’:3}

Now remove the values to get a set.

Set:={‘A’, ‘B’, ‘C’}

A dict demands that all the keys be unique. Set also has a similar demand on the uniqueness of members. Setting key=member one can establish a super-class subclass relation between dict and set.

Tuple is a special case of list, wherein modifications are not allowed. So we can establish a super-class subclass relation between list and tuple.

We are now left with two collection types:

  1. List
  2. Dict

A list looks something like this: [‘ABC’, ‘XYZ’, ‘A1B2’]

If we assume index=key then the above may be expressed as {0:’ABC’, 1:’XYZ’, 2:’A1B2′}

--

--

Shantanu Sen

I was born with a curious and carnivorous mind. A career in IT gave me an opportunity to feed it liberally. From PHP to OData, everything got accommodated.