Created
November 21, 2020 03:27
-
-
Save Gerst20051/7e0bb97c5436d2a4aaff3c66c3c086e8 to your computer and use it in GitHub Desktop.
Get Shifted String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
# | |
# Complete the 'getShiftedString' function below. | |
# | |
# The function is expected to return a STRING. | |
# The function accepts following parameters: | |
# 1. STRING s | |
# 2. INTEGER leftShifts | |
# 3. INTEGER rightShifts | |
# | |
def getShiftedString(s, leftShifts, rightShifts): | |
leftShifts = leftShifts % len(s) | |
rightShifts = rightShifts % len(s) | |
while leftShifts: | |
s = s[1:] + s[0] | |
leftShifts -= 1 | |
while rightShifts: | |
s = s[-1] + s[:-1] | |
rightShifts -= 1 | |
return s | |
if __name__ == '__main__': | |
print(getShiftedString('abcd', 1, 2)) # dabc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment