Skip to content
Advertisement

How to compare items with values of list of dict in python

I have a output list of dicts:

JavaScript

Above data contains info about the attribute i.e. Current NAV Amount Requested, its value and its status. I have a below input list of dict:

JavaScript

I have to compare the value of Current NAV and Amount Requested from fieldValList with outList so that I get the output of how many values from outList are closer to Current NAV value i.e. 33. In this case it is 22, 25, 31 are closer to 33 while values 55, 65 are far from it and thus Confirmed status becomes 3/5 while Rejected becomes 2/5. Similarly for Amount Requested 55, 65, 50 are closer to 45 while 80, 90 are far from it and thus Confirmed status becomes 3/5 while Rejected becomes 2/5.

I am not getting any ideas on how I can proceed to build a logic for this. Please any suggestions thanks.

Advertisement

Answer

Similarly for Amount Requested 55, 65, 50 are closer to 45 while 80, 90 are far from it and thus Confirmed status becomes 3/5 while Rejected becomes 2/5.

Does it mean you want to get fractions of ‘status’ from ‘outList’ for each name from ‘fieldValList’? If so then this is a tip:

JavaScript

Otherwise, you should, as already mentioned, define the criteria for what is considered as “closer”.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement