Q:

Filter dictionary to contain keys present in the given list using python programming

0

Filter dictionary to contain keys present in the given list

Given:

# Dictionary
d1 = {'A': 65, 'B': 66, 'C': 67, 'D': 68, 'E': 69, 'F': 70}

# Filter dict using following keys
l1 = ['A', 'C', 'F']

Expected Output: -

new dict {'A': 65, 'C': 67, 'F': 70}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

# Dictionary
d1 = {'A': 65, 'B': 66, 'C': 67, 'D': 68, 'E': 69, 'F': 70}
# Filter dict using following keys
l1 = ['A', 'C', 'F']
new_dict = {key: d1[key] for key in l1}
print(new_dict)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Print the following number pattern using python pr... >>
<< Display all duplicate items from a list using pyth...