I have a nested list where I receive a data, but that list can change itself. How to get some values if list changes?
alltext=[{
"name": "sample string 1",
"relationships": [
{
"isBlocked": False,
"orderIndex": 1,
"relationship": {
"debts": [
{
"currency": {
"id": "sample string2",
"isoCode": "string",
"isoNumber3": "string",
"name": "string"
},
#"sum"#: 0.0
}
],
"deferment": 90,
"id": "string",
#"name"#: "string 1",
"overdueDebts": [
{
"currency": {
"id": "string",
"isoCode": "string",
"isoNumber3": "string",
"name": "string"
},
#"sum"#: 1000.0
}
],
"vendorId": "string"
}
},
{
"isBlocked": False,
"orderIndex": 2,
"relationship": {
"debts": [
{
"currency": {
"id": "string",
"isoCode": "string",
"isoNumber3": "string",
"name": "string"
},
#"sum"#: 0.0
}
],
"deferment": 90,
"id": "string",
"limit": 0.0,
#"name"#: "string ",
"overdueDebts": [
{
"currency": {
"id": "string",
"isoCode": "string",
"isoNumber3": "string",
"name": "string"
},
#"sum"#: 2000.0
}
],
"vendorId": "string"
}
}
]
}
]
I was trying to do it as example it
for i in range(len(alltext)):
ordersname.append(alltext[i]['relationships'][0]['relationship']['name'])
or like it:
Debts.append([routeDict['sum'] for routeDict in alltext[i]['relationships'][0]['relationship']['debts']])
OverdueDebts.append([routeDict['sum'] for routeDict in alltext[i]['relationships'][0]['relationship']['overdueDebts']])
I have understandent that I think that all because [0]
and I always take first values. If O delete [0]
I receive error TypeError: list indices must be integers or slices, not str
I want to get sum from Debts and OverdueDebts and Name from all relationship(I tagged all things that I want to have