Write a program to capitalize the first and last character of each key in a dictionary


Topic: Write a program to capitalize the first and last character of each key in a dictionary

Solution

input_dict = {'key_a': 10, 'kEy': 2, 'Key_B': 13}
for key in list(input_dict.keys()):
  new_key = key[0].upper() + key[1:-1] + key[-1].upper()
  input_dict[new_key] = input_dict[key]
  if key != new_key:
    del input_dict[key]



List all Python Programs