DEV Community

Discussion on: Interview Qs Decoded - # 2

cat profile image
Cat Author

Yesss I was waiting for a Python response!!!

hammertoe profile image
Matt Hamilton

Actually just realised an even more concise way in Python. The slice operator takes a step as an optional 3rd argument, and I just found out the step can be negative.

>>> str = "Reverse me!"
>>> str[::-1]
'!em esreveR'


def revFunction(str):
  return str[::-1]