From f1ad25cb9e026c474c45f45d9c2e5788382b1fae Mon Sep 17 00:00:00 2001 From: Sapan Desai <35861214+sapan17@users.noreply.github.com> Date: Fri, 30 Oct 2020 10:48:57 +0530 Subject: [PATCH] Create Reverse words in a string.py Reverses individual words in a string while the position of the words remain the same --- Reverse words in a string.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Reverse words in a string.py diff --git a/Reverse words in a string.py b/Reverse words in a string.py new file mode 100644 index 0000000..c001d3d --- /dev/null +++ b/Reverse words in a string.py @@ -0,0 +1,11 @@ +class Solution(object): + def reverseWords(self, s): + """ + :type s: str + :rtype: str + """ + s = s.split() + for i in range(len(s)): + s[i]=s[i][::-1] + return " ".join(s) +