FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sandbox/src/circle_shift.py at master · akafael/python-sandbox · GitHub
akafael
/
python-sandbox
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-sandbox
/
src
/
circle_shift.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (32 loc) · 842 Bytes
Breadcrumbs
python-sandbox
/
src
/
circle_shift.py
Copy path
File metadata and controls
43 lines (32 loc) · 842 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
Left-Right Circle Shift
@author Rafael
"""
#!/bin/python3
def
getShiftedString
(
s
,
leftShifts
,
rightShifts
):
"""
Generate the string after the following operations
1. Left Circle Shift
2. Right Circle Shift
:type s: string
:type leftShifts: int
:type rightShifts: int
Examples:
>>> getShiftedString("abc",1,0)
'bca'
>>> getShiftedString("abc",1,7)
'abc'
"""
# Limit Huge Shifts
sLen
=
len
(
s
)
leftShifts
=
leftShifts
%
sLen
rightShifts
=
rightShifts
%
sLen
# Generate Left shifted string
leftS
=
s
[
leftShifts
:]
+
s
[:
leftShifts
]
# Generate Right shifted string
rightS
=
leftS
[
-
rightShifts
:]
+
leftS
[
0
:
-
rightShifts
]
return
rightS
if
__name__
==
'__main__'
:
# Test Trivial Cases with doctest
import
doctest
doctest
.
testmod
()
Back
|
FazBrowse Home
|
New Git URL