Here is the type of request I want to execute, written in pseudocode:
select blob from blobs where blob['color'] == 'red' having maximum(blob['size'])
Obviously, I could write like this in python:
redBlobs = []; for blob in blobs: if blob['color'] == 'red': redBlobs.append('blob') largestBlob = None for redBlob in redBlobs: if largestBlob == None or redBlob['size'] > largestBlob['size']: largestBlob = redBlob return largestBlob
But I suspect there is a cleaner way to do this. I am new to python, so I am still very against it.
EDIT:
Here is a solution I came up with when looking at other questions about SO:
max([blob for blob in blobs if blob['color'] == 'red'], key = lambda b: b['size'])
There are supposedly better ways.
source share