0

I have a question, I have two arrays, first is initial and second is a calculated result of the first array. so I want to sort the second array and first at the same time. the arrange of these arrays like C[0] calculated by array F[0] when C[0] in sorting changed he location, F[0] also sorting and located like C[0], what can I do for this problem?

F = [[4, '33230201', '31331313', '31330232', '23231310', '12001113', '23333321', '03113303', '2432122', '20133000', '11001233', '10202310', '12331303', '01001101', '10310031'],[4, '33230201', '31331313', '31330232', '23231310', '12001113', '23333301', '03113303', '23021322', '20133000', '11001233', '10202310', '12331303', '01003213', '10310031'] ,[4, '33230201', '31331313', '31330232', '23231310', '12001113', '23333321', '03113303', '23021322', '20133000', '11001233', '10202310', '12331303', '01001101', '10310031']]

C = [[0.8571324934320377, 212, 118],[0.9671324934320377, 232, 111] , [0.8671324934320377, 232, 111]]

How to sort a list according to another list? isn't my answer the question.

Suppose that when the C[0] sorted and displaced by C[2] , the element of F[0] also displaced by F[2], each element of C and F has relation to another. so when elements sorted in array C also element in array F have to sort without destroying relation between them.

Community
  • 1
  • 1
arash askari
  • 17
  • 1
  • 1
  • 7

1 Answers1

2

The question is not very clear, given the current description of it, I would suggest you zip the 2 arrays F, C using zip https://realpython.com/python-zip-function/ and then use sort or sorted depending on if you wish to sort in place or return a new array.

You can find this helpful: Is it possible to sort two lists(which reference each other) in the exact same way?

list1, list2 = zip(*sorted(zip(list1, list2)))

Nir Orman
  • 166
  • 2
  • 10