“Daftar 2D Python Sort” Kode Jawaban

urutkan berdasarkan indeks python array 2d

a = [[9, 9, 2], [9, 9, 3], [9, 9, 8], [9, 9, 4], [9, 9, 1], [9, 9, 5]]

b = sorted(a, key=lambda a:a[2])

#b contains the following arrays, sorted by their second index:
[[9, 9, 1], [9, 9, 2], [9, 9, 3], [9, 9, 4], [9, 9, 5], [9, 9, 8]]
QuietHumility

Daftar 2D Python Sort

data = [['ABC', 12, 3, 100],
        ['DEF', 10, 5, 200],
        ['GHI', 13, 3, 1000]]

data.sort(key=lambda row: (row[2], row[3]), reverse=True)

print(data)

# [['DEF', 10, 5, 200], ['GHI', 13, 3, 1000], ['ABC', 12, 3, 100]]
Kodi4444

Jawaban yang mirip dengan “Daftar 2D Python Sort”

Pertanyaan yang mirip dengan “Daftar 2D Python Sort”

Lebih banyak jawaban terkait untuk “Daftar 2D Python Sort” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya