We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Basic Data Types
- Nested Lists
- Discussions
Nested Lists
Nested Lists
+ 0 comments My idea is that first, I create 2 lists called student and test. The student list contains name and score, while the test list only contains score. Then the test list's duplicated scores will be removed and this list will be sorted in ascending order. Next, I set the second_lowest_score (i) to be the second value of that list (or test[1]). After that, I loop through the student list and find the name that have the satisfied score and order those name alphabetically.
if __name__ == '__main__': # store student's information in a list student = [] test = [] for _ in range(int(input())): name = input() score = float(input()) student.append([name,score]) test.append(score) # Remove duplicates and sort scores in increasing order test = sorted(list(set(test))) # i = second lowest grade; store all the satisfied names in list_name i = test[1] list_name = [] for a in student: if a[1] == i: list_name.append(a[0]) # Order their names alphabetically list_name.sort() for name in list_name: print(name)
+ 0 comments if name == 'main': student = [] for _ in range(int(input())): name = input() score = float(input()) student.append([name, score])
marks=[] for k in student: marks.append(k[1]) second_highest=sorted(set(marks))[1] name=[] for i in student: if i[1]==second_highest: name.append(i[0]) for name in sorted(name): print(name)
+ 0 comments if __name__ == '__main__': records = [] for _ in range(int(input())): name = input() score = float(input()) records.append([name,score]) # guardo los datos en una lista anidada # encontrar puntaje mas bajo scores = [record[1] for record in records] second_lowest_score = sorted(set(scores))[1] #buscar los registros con el mismo puntaje y almacenarlos en una lista auxiliar same_scores_records = [record for record in records if record[1] == second_lowest_score] # ordenar alfabeticamente la lista auxiliar en funcion de los nombres same_scores_records.sort() # imprimir los registros con el segundo puntaje mas bajo y los nombres en orden alfabetico for record in same_scores_records: name, score = record print(name)
+ 0 comments if __name__ == '__main__': student = [] for _ in range(int(input())): name = input() score = float(input()) student.append([name, score]) # print(student) # Make an Empty List which stores the Marks marks = [] for k in student: # Value = k[1] marks.append(k[1]) # From the marks we will get the second minimun Value and store it second_min = sorted(set(marks))[1] # We will store the Name, Which has same marks as Second minimun name = [] for i in student: if i[1] == second_min: name.append(i[0]) # print(name) # Print the name in Alphabetical order for name in sorted(name): print(name)
+ 0 comments python_students = [] for _ in range(int(input())): name = input() score = float(input()) python_students.append([name, score]) ordered_score = sorted(set([scr for _, scr in python_students])) second_lowest_score = sorted([nm for nm, scr in python_students if scr == ordered_score[1]]) print(*second_lowest_score, sep = '\n')
Load more conversations
Sort 3519 Discussions, By:
Please Login in order to post a comment