I have a list of dictionary in Python as below:
List = [
{
'id': 0,
'value': 10
},
{
'id': 1,
'value': 20
},
{
'id': 2,
'value': 80
},
{
'id': 3,
'value': 115
},
{
'id': 4,
'value': 130
},
{
'id': 5,
'value':135
},
{
'id': 6,
'value':250
},
{
'id': 7,
'value':280
}
]
The final output requirement is to check the difference between the value from the first dictionary and other values from the subsequent dictionaries whereby the difference must be <=50, in order to be categorized in the same list (forming a new list).
The expected output is as shown below.
[
[
{
'id': 0,
'value': 10
},
{
'id': 1,
'value': 20
}
],
[
{
'id': 2,
'value': 80
},
{
'id': 3,
'value': 115
},
{
'id': 4,
'value': 130
},
],
[
{
'id': 5,
'value':135
}
],
[
{
'id': 6,
'value':250
},
{
'id': 7,
'value':280
}
]
]
I hope someone can help with this! Thank you.