nipunsadvilkar
7/22/2016 - 6:10 AM

Replacing list elements with key:value elements of dictionary

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']