class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
d=[]
words=s.split()
for i in words:
d.append(i[::-1])
print d
result=" ".join(d)
return result
Error:
UnboundLocalError: local variable 'result' referenced before assignment
Edit:-
result=" ".join(d)
print result
When I used this code in the last two lines I can see my stdout but null value is being returned and when I used these two lines in place of above:
result=" ".join(d)
return result
I get only the first word of the line.
Ex. "I am writing a code"
Expected output:- "edoc a gnitirw ma I "
Actual output: "edoc"
swas used that got the error message? (In particular, was it the empty string?)