-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTS_Labs_exercise.py
58 lines (35 loc) · 1.34 KB
/
RTS_Labs_exercise.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class RTS():
# Returns a hash/object/map/etc. with the keys "above" and "below" with
# the corresponding count of integers from the list that are above or below the comparison value
def aboveBelow(self, lst, comparer):
above = 0
below = 0
for i in lst:
if (i > comparer):
above += 1
elif (i < comparer):
below += 1
return {
"above": above,
"below": below
}
# Rotate a string to the right by an offset
# Returns a new string, rotating the characters in the original string to the right
# by the rotation amount, and have the overflow appear at the beginning.
def stringRotation(self,value, offset):
# The portion of the string that isn't going to overflow
base = value[0 : len(value) - offset]
# When rotating right, the right-most characters contained within
# the offset length will overflow
overflow = value[len(value) - offset: ]
return overflow + base
if __name__ == '__main__':
rts = RTS()
test1 = [1, 2000, 300, 17, 39, 16, 59, 50, 5000]
comparer = 40
res1 = rts.aboveBelow(test1, comparer)
print(res1)
test2 = "Hello, World!"
offset = 2
res2 = rts.stringRotation(test2, offset)
print(res2)