Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Adding Elements to a Python Dictionary

# welcome to softhunt.net
# Creating an empty Dictionary
Dictionary = {}
print("Empty Dictionary: ", Dictionary)

# Adding elements one at a time
Dictionary[0] = 'Softhunt'
Dictionary[1] = '.net'
print("
Dictionary after adding 2 elements: ", Dictionary)

# Adding set of values
# to a single Key
Dictionary['Value_set'] = 2, 3, 4
print("
Dictionary after adding 3 elements: ", Dictionary)

# Updating existing Key's Value
Dictionary[2] = 'Greetings'
print("
Updated key value: ", Dictionary)

# Adding Nested Key value to Dictionary
Dictionary[3] = {'Nested' :{'i' : 'Hello', 'ii' : 'User'}}
print("
Adding a Nested Key: ", Dictionary)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Adding #Elements #Python #Dictionary
ADD COMMENT
Topic
Name
3+9 =