texts = [
'  return a + b',
' ',
'def sub(a, b):',
'  retturn a - b',
' '
]


def left_rotate_normal(texts, rotate_len):
copy = texts[:rotate_len]
texts[:len(texts) - rotate_len] = texts[rotate_len:]
texts[len(texts) - rotate_len:] = copy

test_texts = texts[:]
print(test_texts)
left_rotate_normal(test_texts, 3)
print(test_texts)

['def add(a, b):', '  return a + b', ' ', 'def sub(a, b):', '  retturn a - b', ' ']
['def sub(a, b):', '  retturn a - b', ' ', 'def add(a, b):', '  return a + b', ' ']


def left_rotate_jump(texts, rotate_len):
i = 0
while i < rotate_len:
temp = texts[i]
j = rotate_len
k = i
while j < len(texts):
texts[k] = texts[j]
k = j
j *= 2
texts[j // 2] = temp
i += 1

test_texts = texts[:]
print(test_texts)
left_rotate_jump(test_texts, 3)
print(test_texts)

['def add(a, b):', '  return a + b', ' ', 'def sub(a, b):', '  retturn a - b', ' ']
['def sub(a, b):', 'def add(a, b):', '  return a + b', ' ', '  retturn a - b', ' ']


def left_rotate_reverse(texts, rotate_len):
reverse(texts, 0, rotate_len - 1)
reverse(texts, rotate_len, len(texts) - 1)
reverse(texts, 0, len(texts) - 1)

def reverse(texts, start, end):
while start < end:
temp = texts[start]
texts[start] = texts[end]
texts[end] = temp
start += 1
end -= 1

test_texts = texts[:]
print(test_texts)
left_rotate_reverse(test_texts, 3)
print(test_texts)

['def add(a, b):', '  return a + b', ' ', 'def sub(a, b):', '  retturn a - b', ' ']
['def sub(a, b):', '  retturn a - b', ' ', 'def add(a, b):', '  return a + b', ' ']


import timeit
import random

nums = [random.randint(0, 10000) for i in range(10000)]

def test_left_rotate_reverse():
test_nums = nums[:]
left_rotate_reverse(nums, random.randint(0, len(test_nums)))

def test_left_rotate_jump():
test_nums = nums[:]
left_rotate_jump(nums, random.randint(0, len(test_nums)))

def test_left_rotate_normal():
test_nums = nums[:]
left_rotate_normal(nums, random.randint(0, len(test_nums)))

print(timeit.timeit('test_left_rotate_reverse()', number=1000, setup="from __main__ import test_left_rotate_reverse"))
print(timeit.timeit('test_left_rotate_jump()', number=1000, setup="from __main__ import test_left_rotate_jump"))
print(timeit.timeit('test_left_rotate_normal()', number=1000, setup="from __main__ import test_left_rotate_normal"))

2.267212925973581
2.8630741160013713
0.15271255999687128