I created the dictionary named as Colors.
Colors = {'col1': 'Red', 'col2': 'Orange', 'col3': 'Yellow', 'col4': 'Yellow'}
Q) Create a new Dictionary object colors_new
from the colors Dictionary, having the keys col1 and col2 (Instruction – Use the fromkeys()
method)? is it possible to use fromkeys()
?
My coding is :
Colors = {'col1': 'Red', 'col2': 'Orange', 'col3': 'Yellow', 'col4': 'Yellow'}
print(Colors)
Col={ }
Colors_new={ }
print(Colors_new)
Colors_new = dict.fromkeys(Colors.keys())
print(Colors_new)
OUTPUT
{'col1': 'Red', 'col2': 'Orange', 'col3': 'Yellow', 'col4': 'Yellow'}
{}
{'col1': None, 'col2': None, 'col3': None, 'col4': None}