Question: PYTHON Given two lists containing the names of states and their corresponding capitals, construct a dictionary which maps the states with their respective capitals. Let's
PYTHON
Given two lists containing the names of states and their corresponding capitals, construct a dictionary which maps the states with their respective capitals. Let's see how to do this using for loops and dictionary comprehension. Hint: you can use zip(iteratorl, iterator2) function, which is an iterator of tuples where the first item in each passed iterator is paired together and return an object. . For example: state = ['Gujarat', 'Maharashtra', 'Rajasthan'] capital = ['Gandhinagar', 'Mumbai', 'Jaipur'] Output: Output Dictionary using for loop: { 'Gujarat': 'Gandhinagar', 'Maharashtra': 'Mumbai', 'Rajasthan': 'Jaipur'}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
