Skip to content

Instantly share code, notes, and snippets.

@antonio-catalano
Created April 14, 2018 13:22
Show Gist options
  • Save antonio-catalano/ec509b1fdbbcfb40f1ca8e71e3a101b0 to your computer and use it in GitHub Desktop.
Save antonio-catalano/ec509b1fdbbcfb40f1ca8e71e3a101b0 to your computer and use it in GitHub Desktop.
from hackerrank site
'''' 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