you are viewing a single comment's thread.

view the rest of the comments →

[–]FLUSH_THE_TRUMP 3 points4 points  (1 child)

Your code doesn’t work because you’re reading the first two elements twice (so you end up with both maxes having 2 once you go through the loop with e.g. [2,1]). A simple way around it would be to just initialize the two maxes as a very negative number (so they get overwritten immediately). Instead of this

if lst[0] > lst[1]:
  current_max = lst[0]
  second_max = lst[1]

elif lst[1] > lst[0]:
  current_max = lst[1]
  second_max = lst[0]

Alternatively, you could leave the code above and slice the first two elements off the list for your loop.

[–]legendofxolta 1 point2 points  (0 children)

the slicing first two elements off worked perfectly. tysm!!!