Here is my attempt using a decorator and a for loop. Put everything in one file.
Implementation details:
def reverse(func):
def reverse_engine(items):
partial_items = []
for item in items:
partial_items = [item] + partial_items
return func(partial_items)
return reverse_engine
Usage:
Example 1:
@reverse
def echo_alphabets(word):
return ''.join(word)
echo_alphabets('hello')
# olleh
Example 2:
@reverse
def echo_words(words):
return words
echo_words([':)', '3.6.0', 'Python', 'Hello'])
# ['Hello', 'Python', '3.6.0', ':)']
Example 3:
@reverse
def reverse_and_square(numbers):
return list(
map(lambda number: number ** 2, numbers)
)
reverse_and_square(range(1, 6))
# [25, 16, 9, 4, 1]