Last active
May 14, 2019 19:19
-
-
Save lucas404x/284166c22ccf18b39e69b2e4e8564e05 to your computer and use it in GitHub Desktop.
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
""" | |
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: | |
1: Sort based on name; | |
2: Then sort based on age; | |
3: Then sort by score. | |
The priority is that name > age > score. | |
If the following tuples are given as input to the program: | |
Tom,19,80 | |
John,20,90 | |
Jony,17,91 | |
Jony,17,93 | |
Json,21,85 | |
Then, the output of the program should be: | |
[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')] | |
""" | |
def convertTuple(dates): | |
tuples = [] | |
for date in range(len(dates["name"])): | |
tuple_convert = [] | |
##ADD DATES | |
tuple_convert.append(dates["name"][date]) | |
tuple_convert.append(dates["age"][date]) | |
tuple_convert.append(dates["points"][date]) | |
tuples.append(tuple(tuple_convert)) | |
return tuples | |
def filterDates(dates): | |
dates_filtered = {"name":[], "age":[], "points":[]} | |
dates_aux = dates | |
dates_aux["name"].sort() | |
for date in range(len(dates_aux["name"])): | |
pass | |
return dates_filtered | |
##Begin Programm | |
dates = {"name":[], "age":[], "points":[]} | |
while True: | |
date = input("Enter with the dates: ").split(",") | |
if "" in date: | |
break | |
dates["name"].append(date[0]) | |
dates["age"].append(date[1]) | |
dates["points"].append(date[2]) | |
print(dates) | |
dates = convertTuple(filterDates(dates)) | |
print(dates) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment