I am creating a dictionary object, it gets created while I use "Statement 1", however I get an error message while try create a dictionary object using same keys and values with "Statement 2".
Statement 1:
dmap = {0: 'Mon', 1: 'Tue', 2: 'Wed', 3: 'Thu',
4: 'Fri', 5: 'Sat', 6: 'Sun'}
Statement 2:
dmap = dict(0='Mon', 1='Tue', 2='Wed', 3='Thu',
4='Fri', 5='Sat', 6='Sun'
Error message:
File "<stdin>", line 1
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
Can someone tell me, why am I allowed to create dictionary with integer keys using Statement 1, but not with Statement 2?
Edited Using an updated version of Statement 2, I am able to create dictionary object with below code:
dmap = dict(day_0='Mon', day_1='Tue', day_2='Wed',
day_3='Thu', day_4='Fri', day_5='Sat', day_6='Sun')
I ran into the problem because of a missing comma in my dictionary:
item = {
'a': 1,
'b': 2
'c': 3,
'd': 4
}
Note the missing comma between 2 and 'c'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With