Загрузка...

Finding Students with Second Lowest Grade – One-Liner Version #Python #HackerRank #NestedLists

This video presents a compact one-liner solution for the HackerRank problem of identifying student(s) with the second lowest grade. We efficiently build a nested list from the input, determine the second lowest grade using set operations and sorting, and then print the student names in alphabetical order – all in one concise code snippet.

How It Works:
Input & List Construction:

Read the number of students and build the nested list by reading names and grades.

#InputHandling #ListComprehension

One-Liner Extraction:

Utilize set and list comprehensions along with sorting to identify and print the names of students with the second lowest grade.

#OneLiner #PythonTricks

Output:

The result is printed with each name on a new line.

#Output #Result

Copy and paste the code below into your Jupyter Notebook to try the compact solution!

Code for Compact One-Liner Version (Copy-Paste in Jupyter Notebook):

if __name__ == '__main__':
students = [[input().strip(), float(input().strip())] for _ in range(int(input().strip()))]
[print(name) for name in sorted([s[0] for s in students if s[1] == sorted({s[1] for s in students})[1]])]

Видео Finding Students with Second Lowest Grade – One-Liner Version #Python #HackerRank #NestedLists канала CodeVisium
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять