Computer Science, asked by spratyush5008, 4 months ago

dictionary = { }
dictionary[1] = 1
dictionary['1'] = 2
dictionary[1] + = 1
sum
= 0
for k in dictionary:
sum
+= dictionary[k]
print (sum)​

Answers

Answered by Jasleen0599
0

Python Code

dictionary = {}

dictionary[1] = 1

dictionary['1'] = 2

dictionary[1] += 1

sum = 0

for k in dictionary:

sum += dictionary[k]

print (sum)

Output

4

  • Key-value pairs make up a Python dictionary. You will see two approaches to constructing a dictionary in the following two sections. Using a set of curly braces, or, is the first method. The built-in dict() function is the second method.
  • Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Every key-value pair links the key to the corresponding value.

#SPJ1

Similar questions