Quick actions

cmd+k|ctrl+k

Navigation

Languages

dict data structure

Snippet info

Language

Python

Visibility

public

Author

narutouzumakiramen18

Created

2026-05-07T16:48:56.071453Z

Updated

2026-05-07T17:00:40.99104Z

# In dictionaries there is a rule - The key needs to be immutable - It cannot be tinkered in any way.
# We use strings most common as keys because they are immutable and connot be changed.
# we can also use other datatypes instead of a string but if we use a list as a key we get a error in return.

dictionary = {
    'a': [1,2,3],
    'b':'hello',
    'x':True
}
print(dictionary)

my_list = [
    {
    'a': [1,2,3],
    'b':'hello',
    'x':True
    },
    {
    'a': [4,5,6],
    'b':'Goodbye',
    'x':False
    }
]

print(my_list)
print(my_list[0]['a'][2])
print(dictionary['a'][1])

# A key in a dict has to be unique as it represents a bookshelf in that memory space.
# When we give the same value again we overwrite it with the new dict key in that memory space.
dictionary = { '123':123, '123':'hello'}
print(dictionary['123']) # we get hello in the output
INFO