Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python Dictionaries

#Python dictionaries consists of key value pairs tha
#The following is an example of dictionary
state_capitals = {
    'Arkansas': 'Little Rock',
    'Colorado': 'Denver',
    'California': 'Sacramento',
    'Georgia': 'Atlanta'
}

#Adding items to dictionary
#Modification of the dictionary can be done in similar maner
state_capitals['Kampala'] = 'Uganda' #Kampala is the key and Uganda is the value

#Interating over a python dictionary
for k in state_capitals.keys():
    print('{} is the capital of {}'.format(state_capitals[k], k))
Source by www.howtouselinux.com #
 
PREVIOUS NEXT
Tagged: #python #Dictionaries
ADD COMMENT
Topic
Name
7+2 =