1

Suppose I have the following data in Python 3.3:

my_array = 
   [{'man_id': 1, '_id': ObjectId('1234566'), 'type': 'worker', 'value': 11}, 
   {'man_id': 1, '_id': ObjectId('1234577'), 'type': 'worker', 'value': 12}],

   [{'man_id': 2, '_id': ObjectId('1234588'), 'type': 'worker', 'value': 11}, 
    {'man_id': 2, '_id': ObjectId('3243'), 'type': 'worker', 'value': 7},
    {'man_id': 2, '_id': ObjectId('54'), 'type': 'worker', 'value': 99},
    {'man_id': 2, '_id': ObjectId('9879878'), 'type': 'worker', 'value': 135}],
   #.............................
   [{'man_id': 13, '_id': ObjectId('111'), 'type': 'worker', 'value': 1}, 
    {'man_id': 13, '_id': ObjectId('222'), 'type': 'worker', 'value': 2},
    {'man_id': 13, '_id': ObjectId('3333'), 'type': 'worker', 'value': 9}]

There are 3 arrays. How do I find an element in each array with minimal value?

2 Answers 2

5
[min(arr, key=lambda s:s['value']) for arr in my_array]
Sign up to request clarification or add additional context in comments.

Comments

1

Maybe something like that is acc for you:

for arr in my_array:
   minVal = min([row['value'] for row in arr])
   print [row for row in arr if row['value'] == minVal]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.