In your code, the issue arises from the usage of the dict.fromkeys() method. This method sets the keys of the dictionary to the elements of the iterable passed as the first argument, while assigning the same value to all keys.
In your specific case, when you pass employees[0] (which is 'Kelly') as the iterable to dict.fromkeys(), it interprets the string as an iterable of characters. As a result, each character ('K', 'e', 'l', 'l', 'y') becomes a separate key in the resulting dictionary, all mapped to the same value (defaults).
To resolve this, ensure that you pass the entire employees list as the iterable to dict.fromkeys(). This way, each employee name will be paired with the defaults dictionary correctly.
Here's the code:
employee = ['Kelly', 'Emma', 'John']
defaults = {"designation": 'Application Developer', "salary": 8000}
res_dict = dict.fromkeys(employees, defaults)
print(res_dict)
With this modification, the output will be:
{'Kelly': {'designation': 'Application Developer', 'salary': 8000}, 'Emma': {'designation': 'Application Developer', 'salary': 8000}, 'John': {'designation': 'Application Developer', 'salary': 8000}}
Now, each employee name in the employees list is correctly associated with the defaults dictionary.