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.
it is called list comprehensions.
syntax is : [ expression for item in list if conditional ]
First it compares every values with second lowest value if it is true then it copies new name object which is Harry and Berry in new list then it sorts by name.
'\n'.join prints each object from new list with new line.
Nested Lists
You are viewing a single comment's thread. Return to all comments →
Lets first break whole code into pieces.
it creates nested lists.
students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41.0], ['Harsh', 39.0]]
First it removes repeated values and sort by their values. so sorted list becomes [37.2, 37.21, 39.0, 41.0].
then it copies 2nd element as second lowest value which is 37.21 to compare whether it has more than one student or not.
it is called list comprehensions. syntax is : [ expression for item in list if conditional ]
First it compares every values with second lowest value if it is true then it copies new name object which is Harry and Berry in new list then it sorts by name.
'\n'.join prints each object from new list with new line.
For more information, you can refer below link.
list comprehensions in python