diff --git a/LeetCode/0151_Reverse_Words_in_a_String.py b/LeetCode/0151_Reverse_Words_in_a_String.py new file mode 100644 index 0000000..6e624f4 --- /dev/null +++ b/LeetCode/0151_Reverse_Words_in_a_String.py @@ -0,0 +1,10 @@ +class Solution: + def reverseWords(self, s): + list_of_string = s.split(' ') + #appliying filter function to remove extraspaces from list + new_list = list(filter(lambda x : True if (x!="") else False, list_of_string)) + #taking reverse of output list + new_list.reverse() + #joining the elements if list + final_string = " ".join(str(k) for k in new_list) + return final_string