0

code:

marks = [[ input() , float(input()) ] for _ in range(int(input()))]

s = ( y for [x,y] in marks)

print(s)

l = list(s)
l.sort() 

print(l)

sec = l[1]
ans = [x for [x,y] in marks if y == sec]

ans.sort()
for x in ans:
print(x)

output:

5
Harry
37.21
Berry
37.21
Tina
37.2
Akriti
41
Harsh
39

<generator object <genexpr> at 0x0000020B9232B888>

[37.2, 37.21, 37.21, 39.0, 41.0]
Berry
Harry
idjaw
  • 25,487
  • 7
  • 64
  • 83
Jesira ruhi
  • 11
  • 1
  • 4
  • 6
    That's the string representation of a generator object. You need to iterate the generator to get values out of it. – Carcigenicate Jul 25 '17 at 16:30
  • Here is some reading to understand generators: https://stackoverflow.com/questions/1756096/understanding-generators-in-python – idjaw Jul 25 '17 at 16:31
  • Your use of parentheses for the comprehension that you stored in s results in a generator object. If you'd used square brackets, it would have resulted in the list that your later list(s) call makes. So, you can combine those lines by changing the parentheses to square brackets. – Alan Leuthard Jul 25 '17 at 16:44

0 Answers0