Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

comparing list and dictionary python

# Comparing lists and dictionaries
# We create an empty list and an empty dictionary
lst = []                    # Other way is lst = list()
dictionary = {}             # Other way is dictionary = dict()
# adding items to the list
lst.append(25)
lst.append(34)
print(lst)                  # Output: [25, 34]
# adding values to a dictionary using keys
dictionary['first'] = 25
dictionary['second'] = 34
print(dictionary)           # Output: {'first': 25, 'second': 34}
# Change an item using index in list
lst[0] = 23
print(lst)                  # Output: [23, 34]
# Change a value using key in dictionary
dictionary['first'] = 34
print(dictionary)           # Output: {'first': 34, 'second': 34}
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #comparing #list #dictionary #python
ADD COMMENT
Topic
Name
1+5 =