Search for the Fundamental Collection
Python offers four standard collections, which can be used as native data types.
- List
- Dict
- Set
- 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:
- List
- 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′}