|
1 | | -You are required to write a program to sort the (name, age, height) tuples by ascending order where name is string, age and height are numbers. The tuples are input by console. The sort criteria is: |
2 | | -1: Sort based on name; |
3 | | -2: Then sort based on age; |
4 | | -3: Then sort by score. |
| 1 | +# `38` Sort Tuples Ascending |
| 2 | + |
| 3 | + |
| 4 | +## :pencil: Instructions: |
| 5 | +You are required to write a program to sort the (`name`, `age`, `height`) tuples by ascending order where name is `string`, age and height are numbers. The tuples are input by console. The sort criteria is: |
| 6 | + |
| 7 | +1. Sort based on name; |
| 8 | +2. Then sort based on age; |
| 9 | +3. Then sort by score. |
5 | 10 | The priority is that name > age > score.
|
6 | 11 | If the following tuples are given as input to the program:
|
7 | | -Tom,19,80 |
8 | | -John,20,90 |
9 | | -Jony,17,91 |
10 | | -Jony,17,93 |
11 | | -Json,21,85 |
12 | | -Then, the output of the program should be: |
13 | | -[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')] |
| 12 | +> - `Tom,19,80` |
| 13 | +> - `John,20,90` |
| 14 | +> - `Jony,17,91` |
| 15 | +> - `Jony,17,93` |
| 16 | +> - `Jason,21,85` |
| 17 | + |
| 18 | +> - Then, the output of the program should be: |
| 19 | +`[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Jason', '21', '85'), ('Tom', '19', '80')]` |
14 | 20 |
|
15 | | -Hints: |
| 21 | +## :bulb: Hint: |
16 | 22 | In case of input data being supplied to the question, it should be assumed to be a console input.
|
17 | 23 | We use itemgetter to enable multiple sort keys.
|
0 commit comments