Computer Science, asked by srivallipichaiyan07, 3 months ago

Which one of the following is correct? *

a) In python, a dictionary can have two same keys with different values.

b) In python, a dictionary can have two same values with different keys

c) In python, a dictionary can have two same keys or same values but cannot have two same key-value pair

d) In python, a dictionary can neither have two same keys nor two same values.

Answers

Answered by SidharthSK1122
2

Answer:

b)

Explanation:

In python, a dictionary can have two same values with different keys

Answered by BrainlyYoda
2

b) In Python, a dictionary can have two same values with different keys

Explanation

a) In Python, a dictionary can have two same keys with different values.

Day = {1: 'monday', 1: 'tuesday', 3: 'wednesday'}

print(Day)

Output

{1: 'tuesday', 3: 'wednesday'}

Expected Output

{1: 'monday', 1: 'tuesday', 3: 'wednesday'}

So, we can conclude that this statement is not correct and the dictionary requires unique keys. Also, here the key '1' is getting overwritten by a new value 'tuesday'.

b) In Python, a dictionary can have two same values with different keys

Day = {1: 'monday', 2: 'monday', 3: 'wednesday'}

print(Day)

Output

{1: 'monday', 2: 'monday', 3: 'wednesday'}

Expected Output

{1: 'monday', 2: 'monday', 3: 'wednesday'}

So, we can conclude that this statement is correct and the dictionary can have two same values with different keys

c) In Python, a dictionary can have two same keys or same values but cannot have two same key-value pair

Day = {1: 'monday', 1: 'monday', 3: 'wednesday'}

print(Day)

Output

{1: 'monday', 3: 'wednesday'}

Expected Output

{1: 'monday', 1: 'monday', 3: 'wednesday'}

So, we can conclude that this statement is not correct as the dictionary can have the same values but, not same keys and also cannot have two same key-value pair

d) In Python, a dictionary can neither have two same keys nor two same values.

Day = {1: 'monday', 1: 'tuesday', 3: 'wednesday'}

Day1 = {1: 'monday', 2: 'monday', 3: 'wednesday'}

print(Day)

print(Day1)

Output

{1: 'tuesday', 3: 'wednesday'}

{1: 'monday', 2: 'monday', 3: 'wednesday'}

Expected Output

{1: 'monday', 1: 'tuesday', 3: 'wednesday'}

{1: 'monday', 2: 'monday', 3: 'wednesday'}

So, we can conclude that this statement is not correct as the dictionary

can have two same values but, cannot have two same keys.

Extra Information

Dictionary in Python is used to store data values in an unordered collection. For storing data in a dictionary keys are used. It's like a key: value pair in which data is held by unique keys.

In this Day = {1: 'monday', 2: 'tuesday', 3: 'wednesday'}

Day is a dictionary that has keys 1, 2 and 3 and its values are monday, tuesday, and wednesday respectively.

Example

d1 = {"abc":5,"def":6,"ghi":7}

d1 is a dictionary that has keys abc, def, and ghi and its values are 5, 6, and 7 respectively.

Python is created by Guido van Rossum and came into existence in 1991. It is a high-level and general programming language. It is a very lucid programming language as it has a good language construct and object-oriented approach. It is dynamically typed and garbage-collected.

Similar questions