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.
Imagine the current content of top2 is [1, 2] and logScore is passed a value of 2. The first list comprehension returns all the scores in top2 which are less than 2: [1]. The second list comprehension returns all the scores in top2 which are greater than 2: [], the empty list. So the result is
[1]+[2]+[]
which means that the contents of top2 don't actually change. logScorereplaces the contents of top2 with the result of that line of code, it doesn't add it to the end of top2.
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 →
Imagine the current content of top2 is [1, 2] and logScore is passed a value of 2. The first list comprehension returns all the scores in top2 which are less than 2: [1]. The second list comprehension returns all the scores in top2 which are greater than 2: [], the empty list. So the result is
which means that the contents of top2 don't actually change. logScore replaces the contents of top2 with the result of that line of code, it doesn't add it to the end of top2.