Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Created November 21, 2020 03:27
Show Gist options
  • Save Gerst20051/7e0bb97c5436d2a4aaff3c66c3c086e8 to your computer and use it in GitHub Desktop.
Save Gerst20051/7e0bb97c5436d2a4aaff3c66c3c086e8 to your computer and use it in GitHub Desktop.
Get Shifted String
#!/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