class Solution: def stringShift(self, s, shift): currentIndex = 0 for sh in shift: if sh[0] == 0: currentIndex += sh[1] else: currentIndex -= sh[1] # Now start reading string from this index (wrapping) and go until len reached retString = "" while len(retString) != len(s): retString += s[(currentIndex % len(s))] currentIndex += 1 return retString s = Solution() print("Expected: cab") print("Got:", s.stringShift("abc", [[0,1], [1,2]]))