tuple vs list vs set vs dict

A list is an ordered collection and written as comma-delimited values enclosed in square brackets. Lists are heterogeneous.

>>> [1, 3, True, 6.5]
[1, 3, True, 6.5]
>>> my_list = [1, 3, True, 6.5]
>>> my_list
[1, 3, True, 6.5]
>>> my_list = [0] * 6
>>> my_list
[0, 0, 0, 0, 0, 0]

Tuples are very similar to lists in that they are heterogeneous sequences of data. The difference is that a tuple is immutable, like a string.

A tuple can't be changed.

Tuples are written as comma-delimited values enclosed in parentheses.

>>> my_tuple = (2, True, 4.96)
>>> my_tuple
(2, True, 4.96)
>>> len(my_tuple)
3
>>> my_tuple[0]
2
>>> my_tuple * 3
(2, True, 4.96, 2, True, 4.96, 2, True, 4.96)
>>> my_tuple[0:2]
(2, True)

Sets are heterogeneous as well and written as comma-delimeted values enclosed in curly braces.

>>> {3, 6, "cat", 4.5, False}
{False, 3, 4.5, 6, 'cat'}
>>> my_set = {3, 6, "cat", 4.5, False}
>>> my_set
{False, 3, 4.5, 6, 'cat'}

Sets are unordered structure.

Dictionary is the same with JSON object, written as comma-delimeted key:value pairs enclosed in curly braces. And it maintains the order the pairs were added.

>>> phone_ext={"david": 1410, "brad": 1137, "roman": 1171}
>>> phone_ext
{'david': 1410, 'brad': 1137, 'roman': 1171}
>>> phone_ext.keys()
dict_keys(['david', 'brad', 'roman'])
>>> list(phone_ext.keys())
['david', 'brad', 'roman']
>>> phone_ext.values()
dict_values([1410, 1137, 1171])
>>> list(phone_ext.values())
[1410, 1137, 1171]
>>> phone_ext.items()
dict_items([('david', 1410), ('brad', 1137), ('roman', 1171)])
>>> list(phone_ext.items())
[('david', 1410), ('brad', 1137), ('roman', 1171)]
>>> phone_ext.get("kent")
>>> phone_ext.get("kent", "NO ENTRY")
'NO ENTRY'