I am very new in Python and I am confused in using .formkeys() method with lists.
Here's my code below:
# dictionary exercise 4: Initialize dictionary with default values
employees = ['Kelly', 'Emma', 'John']
defaults = {"designation": 'Application Developer', "salary": 8000}
def_dictionary = dict()
def_dictionary.setdefault("designation", "Application Developer")
def_dictionary.setdefault("salary", 8000)
print(def_dictionary)
res_dict = dict.fromkeys(employees[0], defaults)
print(res_dict)
print(res_dict)
Here, the output is
{'K': {'designation': 'Application Developer', 'salary': 8000}, 'e': {'designation': 'Application Developer', 'salary': 8000}, 'l': {'designation': 'Application Developer', 'salary': 8000}, 'y': {'designation': 'Application Developer', 'salary': 8000}}
What I want to do is pair employee "Kelly" with the default values dictionary, however, I don't understand why I get 'K', 'E', 'L', 'Y' strings as keys to my res_dict.
I know the solution should be
res_dict = dict.fromkeys(employees, defaults)
I am just wondering why the code parses Kelly to 'K', 'E', 'L', 'Y'.
Thank you