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.
First, two thumbs up for for the detailed explanation, thank you! Now it makes so much sense to me! This is such a nifty way to deal with the problem since the order of the entries are maintained and you know where what is.
I understand what will happen when top2 is empty, that number of elements is irrelevant since you iterate over all the entries in top2 with score and you maintain the order of entries in top2, wether the score is higher or lower than top2, but i'm sure why it'd not add two entries of same value because the first comprehension will give an empty list, score will be score and the third comprehension will give an empty list so it should append score to top2 otherwise the first time the code is run, it wouldn't work in that case too?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nested Lists
You are viewing a single comment's thread. Return to all comments →
First, two thumbs up for for the detailed explanation, thank you! Now it makes so much sense to me! This is such a nifty way to deal with the problem since the order of the entries are maintained and you know where what is.
I understand what will happen when top2 is empty, that number of elements is irrelevant since you iterate over all the entries in top2 with score and you maintain the order of entries in top2, wether the score is higher or lower than top2, but i'm sure why it'd not add two entries of same value because the first comprehension will give an empty list, score will be score and the third comprehension will give an empty list so it should append score to top2 otherwise the first time the code is run, it wouldn't work in that case too?