2

I have a JSON object array as given below:

"results": [
        {
        "BOX_coordinate_LefTop_X": 241,
        "BOX_coordinate_LefTop_Y": 1428,
        "BOX_coordinate_RightBottom_X": 2081,
        "BOX_coordinate_RightBottom_Y": 1738,
        "BOX_language" : "English",
        "OCR_possibility0": "Resident identity Card"
        },

        {
        "BOX_coordinate_LefTop_X": 140,
        "BOX_coordinate_LefTop_Y": 3272,
        "BOX_coordinate_RightBottom_X": 1924,
        "BOX_coordinate_RightBottom_Y": 3481,
        "BOX_language" : "English",
        "OCR_possibility0": "Name: Bhawandeep"
        },

        {
        "BOX_coordinate_LefTop_X": 537,
        "BOX_coordinate_LefTop_Y": 3489,
        "BOX_coordinate_RightBottom_X": 1951,
        "BOX_coordinate_RightBottom_Y": 3686,
        "BOX_language" : "English",
        "OCR_possibility0": "Bhawandeep"
        },

        {
        "BOX_coordinate_LefTop_X": 67,
        "BOX_coordinate_LefTop_Y": 3844,
        "BOX_coordinate_RightBottom_X": 1580,
        "BOX_coordinate_RightBottom_Y": 4091,
        "BOX_language" : "English",
        "OCR_possibility0": "Nationality: Indian"

        }
]

I want to sort this list based on the BOX_coordinate_LefTop_Y.

results.sort(key='BOX_coordinate_LefTop_Y') is not working as expected.

1 Answer 1

7

key for sort is a function, you need to pass a lambda:

results.sort(key=lambda s: s['BOX_coordinate_LefTop_Y'])
Sign up to request clarification or add additional context in comments.

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.