Python dictionary with keys having multiple inputs


When it is required to create a dictionary where keys have multiple inputs, an empty dictionary can be created, and the value for a specific key can be specified.

Below is the demonstration of the same −

Example

 Live Demo

my_dict = {}

a, b, c = 15, 26, 38
my_dict[a, b, c] = a + b - c

a, b, c = 5, 4, 11
my_dict[a, b, c] = a + b - c

print("The dictionary is :")
print(my_dict)

Output

The dictionary is :
{(15, 26, 38): 3, (5, 4, 11): -2}

Explanation

  • The required packages are imported.

  • An empty dictionary is defined.

  • The values for a specific key are specified.

  • The output is displayed on the console.

Updated on: 17-Apr-2021

854 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements