Created
July 22, 2016 06:10
-
-
Save nipunsadvilkar/f6327ed42a67a0a4467945f33143aa3c to your computer and use it in GitHub Desktop.
Replacing list elements with key:value elements of dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
substitute_dictionary = {'EmaIL':'Email ID','PhOne':'Telephone No.','CIty':'City/country'} | |
list_elements = ['EmaIL','PhOne','CIty'] | |
replaced_list_elements = [substitute_dictionary.get(element,item) for element in list_elements] | |
print 'Original List:',list_elements | |
print 'List elements replaced as per dictionary o/p:',replaced_list_elements | |
# Original List: ['EmaIL', 'PhOne', 'CIty'] | |
# List elements replaced as per dictionary o/p: ['Email ID', 'Telephone No.', 'City/country'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment