Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nipunsadvilkar/f6327ed42a67a0a4467945f33143aa3c to your computer and use it in GitHub Desktop.
Save nipunsadvilkar/f6327ed42a67a0a4467945f33143aa3c to your computer and use it in GitHub Desktop.
Replacing list elements with key:value elements of dictionary
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