Nested lists problem solution | Python | HackerRank

Input Format:-

    The first line take input N, Which denote the number of student.

    The 2N subsequent lines describe each student over 2 lines ; and the first line contain name of student ,      and on second line it contain grade of that student.

Constraints:-

 >    2 <= N <= 5 

 >    There will always be one or more student to have the second lowest grade. 

Output Format:-

 Print the name(s) of any student(s) having the second lowest grade in Physics: if there are multiple students,order their name in a order of alphabetically and print each one on  new line.
     
     
Solution Code:-
  
              Note:--   Code is for Python 3

             n = int(input())
             data = list()
             data2 = list()
             for x in range(n):
                 name = input().strip()
                 grade = float(input().strip())
                 data.append(grade)
                 data.sort()
                 data1 = [] 
                 data1.append(name)
                 data1.append(grade)
                 data2.append(data1)
             data2.sort()
             data = set(data)
             data = list(data)
             data.sort()
             marks = data[1]
             for x in data2:
                  if marks in x:
                  print(x[0])
 
 Note:--   Code is for Python 2

   n = int(raw_input())
             data = list()
             data2 = list()
             for x in range(n):
                 name = raw_input().strip()
                 grade = float(raw_input().strip())
                 data.append(grade)
                 data.sort()
                 data1 = [] 
                 data1.append(name)
                 data1.append(grade)
                 data2.append(data1)
             data2.sort()
             data = set(data)
             data = list(data)
             data.sort()
             marks = data[1]
             for x in data2:
                  if marks in x:
                   print(x[0])


ABOUT

Contact By:-- ---   charlievishwakarma.2503@gmail.com
                                         9004350596
Created By:------ shubham vishwakarma(Naime.com) 

Comments

Popular posts from this blog

List problem solution |PYTHON| HackerRank

Recursion 3 Problem solution | 30 days of code| Hacker Rank