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.
foo[i:j:k] gives a slice of list foo from i to j (but not including j) by step k
when i or j is omitted, it takes the whole range, so [::1] means "from first to last". but if k is negative, the order is reversed, so [::-1] means "from last to first"
it's a cute way of getting the list in reverse order, in other words
so then he uses the [1] index to get the second element in the reversed list, which gives the runner-up value
could just have used [-2] instead of forcing the list to be reversed
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
foo[i:j:k] gives a slice of list foo from i to j (but not including j) by step k
when i or j is omitted, it takes the whole range, so [::1] means "from first to last". but if k is negative, the order is reversed, so [::-1] means "from last to first"
it's a cute way of getting the list in reverse order, in other words
so then he uses the [1] index to get the second element in the reversed list, which gives the runner-up value
could just have used [-2] instead of forcing the list to be reversed