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 if __name__ == '__main__': a=[] b=[] for i in range(int(input())): name = input() score = float(input()) a.append([name,score]) b.append(a[i][1]) b.sort() b=set(b) c=list(b) d=[] for i in range(len(a)): if c[1]==a[i][1]: d.append(a[i][0]) d.sort() for i in range(len(d)): print(d[i])
+ 0 comments if name == 'main': result=list() marks=list() for _ in range(int(input())): name = input() score = float(input()) result.append([name,score]) #nested list marks.append(score)
marks=sorted(set(marks)) second_lowest = marks[1]
names=[val[0] for val in result if second_lowest==val[1] ] (or)
names=[name for name,score in result if second_lowest==score ] names.sort() for i in names: print(i)
+ 0 comments if __name__ == '__main__': a=[ ] list_score=[ ] list_score2=[ ] list_sec_low=[ ] for _ in range(int(input())): name = input() score = float(input()) x=[name,score] a.append(x) list_score.append(score) list_score.sort``() e=min(list_score) for i in list_score: if i != e: list_score2.append(i) for c in a: if c[1]==min(list_score2): list_sec_low.append(c[0]) list_sec_low.sort() for d in list_sec_low: print(d)
+ 0 comments if __name__ == '__main__': students = [] marksList = [] for _ in range(int(input())): name = input() marks = float(input()) students.append([name, marks]) marksList.append(marks) secondLowestScore = sorted(set(marksList))[1] x = [sname for sname, marks in students if marks == secondLowestScore] for _ in sorted(x): print(_)
+ 1 comment With comments for clarity
grades = [] answer = [] #add a line in the given loop to add #names and scores to a NESTED LIST for _ in range(int(input())): name = input() score = float(input()) grades.append([name, score]) #sort the nested list by scores, #then by name (in case of a tie) grades.sort(key = lambda l: (l[1], l[0])) #make a SET of just the scores to #remove repeat values (so we will #know which score is 2nd lowest) gradeset = set(grades[i][1] for i in range(len(grades))) #convert the above set into a list #so we can iterate through it uniquelist = list(gradeset) #iterate through the nested list #if the grade in the list is equal #to the second score in the unique #list, add that person's name to #the final answer list for j in range(len(grades)): if grades[j][1] == uniquelist[1]: answer.append(grades[j][0]) #print the names you got from the #above step, each one on a new line for x in answer: print(x)
Load more conversations
Sort 3256 Discussions, By:
Please Login in order to post a comment