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 program, we will create a singly linked list and remove duplicate elements from it. A linked list...
This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...
This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...