-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy56.py
More file actions
24 lines (19 loc) · 759 Bytes
/
py56.py
File metadata and controls
24 lines (19 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#sorting bases on kth element of the list of subset
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())
#key specifies on what basis we need to sort
arr.sort(key=lambda x: x[k]) #lambda x: x[k] is an anonymous function (lambda function) that
#takes one argument x (which will be a sublist) and returns the k-th element of that sublist.
for i in range(len(arr)):
for j in range(len(arr[i])):
print(arr[i][j],end=" ")
print()
# or
for i in arr:
print(*i) #removes the list brackets and prints inner list as a string