HackerRank Athlete sort problem solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Athlete sort problem solution in Python – In this Athlete sort problem, you are given a spreadsheet that contains a list of N athletes and their details (such as age, height, weight, and so on). You are required to sort the data based on the Kth attribute and print the final resulting table. Follow the example given below for better understanding.Note that K is indexed from 0 to M-1, where M is the number of attributes. Note: If two attributes are the same for different rows, for example, if two atheletes are of the same age, print the row that appeared first in the input.Input FormatThe first line contains N and M separated by a space.The next N lines each contain M elements.The last line contains K. HackerRank Athlete sort solution in Python 2.N,M = map(int,raw_input().split()) lines = [] for i in xrange(N): lines.append(map(int,raw_input().split())) K = int(raw_input()) lines = sorted(lines,key = lambda x: x[K]) for line in lines: print ' '.join(str(k) for k in line)Athlete sort solution in Python 3.#!/bin/python3 import math import os import random import re import sys if __name__ == '__main__': nm = input().split() n = int(nm[0]) m = int(nm[1]) arr = [] for _ in range(n): arr.append(list(map(int, input().rstrip().split()))) k = int(input()) P=sorted(arr,key=lambda row:row[k]) for i in range(len(P)): for j in range(len(P[i])): print(P[i][j], end=' ') print()Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT N, M = map(int, raw_input().split()) rows = [raw_input() for _ in range(N)] K = input() for row in sorted(rows, key=lambda row: int(row.split()[K])): print(row)Problem solution in pypy3 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT tbl = [] rc = input() (r,c) = map(int, rc.split()) for i in range(r): _row = input() row = list(map(int, _row.split())) tbl.append(row) idx = int(input()) tbls = sorted(tbl, key = lambda x: x[idx]) for t in tbls: print (*t) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython