Write a function that takes as an input parameter a string and a number n and returns a newly created string made of every nth letter.
Can anyone help?
Write a function that takes as an input parameter a string and a number n and returns a newly created string made of every nth letter.
Can anyone help?
This is quite simple in Python because of the way it handles indexing:
def every_n(s, n):
return s[::n]
That third item between the colons says "every n".
Check out Explain Python's slice notation for a more in depth description of how to slice in Python.