I have a dictionary within a list as below
b = [
{
"ServiceLevel": {
"S": "AA"
},
"ReadyTime": {
"S": "2020-01-31T12:00:00"
},
"DeliveryDate": {
"S": "2020-02-15T12:00:00"
}
}
]
I am trying to access the elements within that inner dictionary and convert them to JSON format: My try:
a = b[0]
for key, value in sorted(a.items()):
a1 = print(key, value)
for i in a1:
b1 = a1[i]
print(b1)
I am trying to get this output:
b = {
"ServiceLevel": "AA",
"ReadyTime": "2020-01-31T12:00:00",
"ReadyDate": "2020-01-31T12:00:00",
}
ERROR : TypeError: 'NoneType' object is not callable
You are assigning print() method to a variable, here is the NoneType error
a1 = print(key, value) # variable a1 is NoneType
for i in a1: # error because variable a1 is not iterable
Use :
b1 = {}
for key, value in b[0].items():
b1[key] = value['S']
print(b1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.