-1

I have a list like this:

[
  [
    ['KAD', 'PENGENALAN'],
    ['0.95', '0.98'],
    [[106, 16, 202, 48], [214, 14, 524, 50]],
    [106, 214]
  ],
  [
    ['word1', 'word2', 'word3'],
    ['0.95', '0.98', '0.99'],
    [[222, 16, 202, 48], [55,14, 524, 50]], [89, 14, 524, 50]]
    [222, 55, 89]
  ]

]

I want to sort items per line by 4th element.

4th element is [106, 214] and [222, 55, 89]

First list is already sorted according to 4th element. I want to sort 2nd list.

In the second list, I want to sort by small to big. I want to sort using [222,55,89]

Expected output is:

[
  [
    ['KAD', 'PENGENALAN'],
    ['0.95', '0.98'],
    [[106, 16, 202, 48], [214, 14, 524, 50]],
    [106, 214]
  ],
  [
    ['word2', 'word3', 'word'],
    ['0.98', '0.99','0.95'],
    [[55,14, 524, 50]], [89, 14, 524, 50],[222, 16, 202, 48]]
    [55, 89,222]
  ]

]

I don't know how I can do this. But can I use zip() and sort? Just giving you some ideas

rahul sharma
  • 109
  • 1
  • 8

1 Answers1

0

I think, I found the answer.

It is something like

finalList = []
for i in range(len(text_line)):
    zipped_pairs = zip(text_line[i][3],text_line[i][0], text_line[i][1],text_line[i][2])
    tempList = []
    for a,b,c,d in sorted(zipped_pairs):
        tempList.append([b,c,d])
    finalList.append(np.array(tempList).T)

Need to arrange it properly

rahul sharma
  • 109
  • 1
  • 8