Created
April 14, 2018 13:22
-
-
Save antonio-catalano/ec509b1fdbbcfb40f1ca8e71e3a101b0 to your computer and use it in GitHub Desktop.
from hackerrank site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''' Here's the problem: https://www.hackerrank.com/challenges/python-sort-sort/problem''' | |
N,M = map(int,input('First number is the number of athletes,\n\ | |
second number is the number of attributes for each atlhete.\nWrite: ').split()) | |
print() | |
print("So we have {} athletes and {} in our database\n".format(N,M)) | |
L = [] | |
for i in range(1,N+1): | |
L.append(list(map(int,input('Write attributes for athlete number {} : '.format(i)).split()))) | |
L_Athletes = dict() | |
for i in range (1,N+1): | |
L_Athletes[tuple(L[i-1])] = 'Athlete number {}'.format(i) | |
k = int(input('Write the attribute to use as sorting-key from 0 to {}: '.format(M-1))) | |
L_sorted = sorted(L, key=lambda elem: elem[k]) | |
print() | |
print("Sorted on the {}th attribute:\n\n".format(k)) | |
print('Attributes sorted by column {} (from 0 to {})'.format(k,M-1).rjust(65)) | |
for elem in L_sorted: | |
print('\n') | |
print(L_Athletes[tuple(elem)],'--->',end = ' ') | |
s = map(str,elem) | |
for i in range(M): | |
print(next(s).center(5), end=' ') | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment