Computer Science
What are the characteristics of Dictionary?
Python Dictionaries
1 Like
Answer
The characteristics of dictionary are as follows:
Each key maps to a value — The association of a key and a value is called a key-value pair. However, there is no order defined for the pairs, thus, dictionaries are unordered.
Each key is separated from its value by a colon (:). The items are separated by commas, and the entire dictionary is enclosed in curly braces {}.
Keys are unique and immutable — Keys are unique within a dictionary while values are mutable and can be changed.
Indexed by Keys — The elements in a dictionary are indexed by keys and not by their relative positions or indices.
The value of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers or tuples.
Dictionary is mutable — We can add new items, delete or change the value of existing items.
Answered By
1 Like
Related Questions
Write a program to count the frequency of a given element in a list of numbers.
Write a program to check if the smallest element of a tuple is present at the middle position of the tuple.
What are the issues associated with disability while teaching and using computers?
Observe the code given below and answer the following questions. A triangle has three sides — a, b and c, and the values are 17, 23 and 30, respectively. Calculate and display its area using Heron's formula as
;
(a) Import the module — Statement 1
(b) Calculate s (half of the triangle perimeter) — Statement 2
(c) Insert function to calculate area — Statement 3
(d) Display the area of triangle — Statement 4
import ............... #Statement 1 a, b, c = 17, 23, 30 s = ............... #Statement 2 area = ............... (s*(s—a)*(s—b)*(s—c)) #Statement 3 print("Sides of triangle:", a, b, c) print(...............) #Statement 4