forked from Ada-Activities/algorithm-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate_list.py
29 lines (22 loc) · 826 Bytes
/
rotate_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Add your clarifying questions here
# ["a", "b", "c"] -> shift_by 2
# ["b", "c", "a"]
# i = shift_by
# ["c","d",]
# 15, 15 - 3 =12,9,6,3
def rotate_list(list, shift_by):
if shift_by > len(list):
shift_by %= len(list)
for i in range(shift_by, len(list)):
rotated_list = [list[shift_by]]
#if shift_by <= len(list)
# if at end of list
# update i with ((len-1) - i)
# if i == shift_by -1
# return rotated_list
#append list[shift_by] to rotated_list
#rotated_list.append(list[i])
assert rotate_list(["a", "b", "c"], 2) == ["b", "c", "a"]
assert rotate_list(["a", "b", "c"], 0) == ["a", "b", "c"]
assert rotate_list(["a", "b", "c"], 3) == ["a", "b", "c"]
assert rotate_list([], 4) == []