You are viewing a single comment's thread. Return to all comments →
Pretty smart, but are you sure you are not copying the kth eleement, in ruby it would be:
def array_left_rotation(a, k)
a[k..-1] + a[0...k]
In ruby, ... means excluding the right number.
Yes both qzangs and my answer is correct. In python index slicing (indices[start:stop:step]), works like so...
We will begin with the index specified at start and traverse to the next index by our step amount (i.e. if step = 2, then we jump over every other element, if step = 3, we jump over 2 elements at a time). If step is not specified it is defaulted to 1. We continue steping from our start point until we come to or exeed our stop point. We do NOT get the stop point, it simply represents the point at which we stop.
I love Python :)
Ok, so it's exclusive by default in Python, interesting.