Python Program to Map Two Lists into a Dictionary

Python dictionaries provide a convenient way to map keys to values. This program demonstrates how to create a Python program that maps two lists into a dictionary, where elements from one list act as keys and elements from another list act as values.

Problem Statement

Write a Python program that takes two lists as input and maps them into a dictionary, where elements from the first list become keys and elements from the second list become values.

Python Program to Map Two Lists into a Dictionary

def map_lists_to_dictionary(keys, values):
    result_dict = {}

    for i in range(len(keys)):
        result_dict[keys[i]] = values[i]

    return result_dict

# Input
keys_list = input("Enter the keys list (comma-separated values): ").split(',')
values_list = input("Enter the values list (comma-separated values): ").split(',')

# Mapping lists to dictionary
mapped_dict = map_lists_to_dictionary(keys_list, values_list)

# Output
print("Mapped dictionary:", mapped_dict)

Input / Output

Python Program to Map Two Lists into a Dictionary

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this python tutorial, you will learn how to Display Prime Numbers Between Two Intervals using the if and else...
In this python tutorial, you will learn how to Calculate Standard Deviation with built in functions of the python programming...
In this Python program, we will convert temperature values from Celsius to Fahrenheit. The Celsius and Fahrenheit scales are two...