304 North Cardinal St.
Dorchester Center, MA 02124
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.
The first line contains N and M separated by a space.
The next N lines each contain M elements.
The last line K contains.
Print the N lines of the sorted table. Each line should contain the space separated elements. Check the sample below for clarity.
5 3 10 2 5 7 1 0 9 9 9 1 23 12 6 5 9 1
7 1 0 10 2 5 6 5 9 9 9 9 1 23 12
The details are sorted based on the second attribute, since K is zero-indexed.
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)
#!/bin/python3 import math import os import random import re import sys if __name__ == '__main__': nm = input().split() n = int(nm) m = int(nm) 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()
# 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)
# 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)
In our experience, we suggest you solve this Athlete Sort Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
I hope this Athlete Sort Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
More Hacker Rank Problem & Solutions >>