[HackerRank] All Domains - Python - Basic Data Types - Nested Lists

2022. 3. 13. 16:22Algorithm

728x90
반응형

Let's implement a nested list! A nested list is a list that contains another list (i.e.: a list of lists). For example:

nested_list = [['blue', 'green'], ['red', 'black'], ['blue', 'white']] print len(a) # prints 3 print nested_list[1] # prints ['red', 'black'] print nested_list[1][0] # prints red 

To go through every element in a list, use a nested for loop.

 

 

------------------------------------------------------------------------------------

def secondlow(students):    grades = []    for student in students:         grades.append(student[1])    sort_grades = sorted(grades)    seclow_grade = sort_grades[0]    for grade in sort_grades:        if grade != seclow_grade:            seclow_grade = grade            break    seclow_stud = []    for student in students:         if student[1] == seclow_grade:            seclow_stud.append(student[0])    for name in sorted(seclow_stud):         print(name)


students = []for pupil in range(int(input())):    new_stud = [input(), float(input())]    students.append(new_stud)secondlow(students)

 

------------------------------------------------------------------------------------

728x90
반응형