Aug-14-2018, 03:14 PM
Need Help on below error
When i write a code like below
Traceback (most recent call last):
File "C:/v586150-Prsnl/learning/python/Vz450inP/kirandic.py", line 3, in <module>
dic1['key1']['key2'] = 'Value1'
KeyError: 'key1'
I am forced to define a subkey definition before assignment. Is there a better approach that Python understand the definition of the type and auto instantiate like Perl
When i write a code like below
dic1 = {} dic1['key1']['key2'] = 'Value1' print(dic1)Below error is encountered
Traceback (most recent call last):
File "C:/v586150-Prsnl/learning/python/Vz450inP/kirandic.py", line 3, in <module>
dic1['key1']['key2'] = 'Value1'
KeyError: 'key1'
I am forced to define a subkey definition before assignment. Is there a better approach that Python understand the definition of the type and auto instantiate like Perl
dic1 = {} dic1['key1'] = {} dic1['key1']['key2'] = 'Value1' print(dic1)Process finished with exit code 1