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.
RazyDave:
The colon, inside an array index, can set up to 3 numbers/parameters:
The first one is the "from" number (included), the second is the "to" number (excluded), and the third is the "pace".
a[::2] will retrieve all array items (since it does not set up any from or to, and set the "pace"), starting from index 0, incrementing the index two by two and accessing all even indexes (0,2,4,6, and so on).
s[1::2] will retrieve all array items, from index 1, incrementing the index two by two and accessing all odd indexes (1,3,5,7,9, and so on).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
RazyDave: The colon, inside an array index, can set up to 3 numbers/parameters:
The first one is the "from" number (included), the second is the "to" number (excluded), and the third is the "pace".