Given:
roll_number = [47, 64, 69, 37, 76, 83, 95, 97] sample_dict = {'Jhon':47, 'Emma':69, 'Kelly':76, 'Jason':97}
Expected Outcome:
After removing unwanted elements from list [47, 69, 76, 97]
Solution:
roll_number = [47, 64, 69, 37, 76, 83, 95, 97] sample_dict = {'Jhon': 47, 'Emma': 69, 'Kelly': 76, 'Jason': 97} print("List:", roll_number) print("Dictionary:", sample_dict) # create new list roll_number[:] = [item for item in roll_number if item in sample_dict.values()] print("after removing unwanted elements from list:", roll_number)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer