[Tutor] Help understanding list comprehensions

Anubhav Yadav anubhav1691 at gmail.com
Tue Jun 16 21:39:13 CEST 2015


I am sorry I didn't posted my code. I had solved this question long back on
hackerrank, and I couldn't figure out why this behaviour was seen in this
problem, so I had posted this question on their discussion forum. Couldn't
get a good answer so I decided to post here. Luckily I found the revision
history of my submission there where I could find the earlier code which
was giving this error.

Here is the code.

marks = [['Varun', 19.0], ['Kakunami', 19.0], ['Harsh', 20.0], ['Beria',
20.0], ['Vikas', 21.0]]
marks = sorted(marks, key=lambda score:score[1])
lowest = marks[0][1]

for row in marks:
    if row[1] == lowest:
        marks.remove(row)

second_lowest = marks[0][1]

sh = []
for row in marks:
    if second_lowest == row[1]:
        sh.append(row)

for row in sorted(sh):
    print row[0]


More information about the Tutor mailing list