During my interview they asked me a implement a function to reverse each word in a sentence and create final sentence from it. For example:
s = 'my life is beautiful'
output - `ym efil si lufituaeb`
I know the question is pretty simple so solved it in few minutes:
s = 'my life is beautiful'
def reverse_sentence(s):
string_reverse = []
for i in s.split():
string_reverse.append("".join(list((reversed(i)))))
print " ".join(string_reverse)
reverse_sentence(s)
Then they asked to implement the same function using a decorator
, and I got confused here. I know the basics of decorator
how it used, and when it used. They didn't mention what part of the function they want to wrap
using decorator
. They told me to implement this using args
and kwargs
, and I was not able to solve it. Could anyone help me here? How can I convert any function into decorator?
As my per knowledge, you use decorator
when you want to wrap your function
or you want to modify the some functionality. Is my understanding correct?