Sort of Sorting
This commit is contained in:
23
sortofsorting.py
Normal file
23
sortofsorting.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from functools import cmp_to_key
|
||||||
|
|
||||||
|
n = int(input())
|
||||||
|
|
||||||
|
|
||||||
|
def sorting_method(a, b):
|
||||||
|
if ord(a[0]) > ord(b[0]):
|
||||||
|
return 1
|
||||||
|
elif ord(a[0]) < ord(b[0]):
|
||||||
|
return -1
|
||||||
|
elif ord(a[1]) > ord(b[1]):
|
||||||
|
return 1
|
||||||
|
elif ord(a[1]) < ord(b[1]):
|
||||||
|
return -1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
while n:
|
||||||
|
names = sorted([input() for _ in range(n)], key=cmp_to_key(sorting_method))
|
||||||
|
for name in names:
|
||||||
|
print(name)
|
||||||
|
print()
|
||||||
|
n = int(input())
|
||||||
Reference in New Issue
Block a user