Complete the function that accepts a string parameter, and reverses each word in the string. **All** spaces in the string should be retained.

## Examples
```
"This is an example!" ==> "sihT si na !elpmaxe"
"double  spaces"      ==> "elbuod  secaps"
```

Difficulty: introductory

Starter code:

def reverse_words(text):
	

Solutions:
def reverse_words(str):
    return ' '.join(s[::-1] for s in str.split(' '))

def reverse_words(str_):
    return ' '.join(s[::-1] for s in str_.split(' '))


import re

def reverse_words(str):
  return re.sub(r'\S+', lambda w: w.group(0)[::-1], str)

def reverse_words(str):
  return ' '.join(w[::-1] for w in str.split(' '))

def reverse_words(str):
  return " ".join(map(lambda word: word[::-1], str.split(' ')))

def reverse_words(str):
  #go for it
  newStr = []
  for i in str.split(' '):
      newStr.append(i[::-1])
  return ' '.join(newStr)

import re

def reverse_words(str):
  return ''.join(word[::-1] for word in re.split(r'(\s+)', str))

def reverse_words(str):
  return ' '.join([i[::-1] for i in str.split(' ')])

def reverse_words(text):
  return ' '.join([ word[::-1] for word in text.split(' ')])

def reverse_words(inString):
    return " ".join(inString[::-1].split(" ")[::-1])

def reverse_words(str):
  #go for it
  return " ".join(["".join(word[::-1]) for word in str.split(" ")])

def reverse_words(string):
  space=' '
  for i in range(len(string)):
      if string[i] == ' ' and string[i+1] == ' ':
          space = '  '
          break
      if string[i] == ' ':
          space = ' '
          break
  lst = string.split()
  for i in range(len(lst)):
      lst[i] = reverse_one_word(lst[i])
  return space.join(lst)
  
  
def reverse_one_word(string):
    reverse = ''
    for i in range(len(string)):
        reverse = string[i] + reverse
    return reverse

def reverse_words(text):
    l = text.split(' ')
    for i in range(len(l)):
        l[i] = l[i][::-1]
    return ' '.join(l)

def reverse_words(text):
    L=[]
    a=text.split(" ")
    for i in a:
        i=i[::-1]
        L.append(i)
    x=" ".join(L)
    return x

import re
import textwrap
def reverse_words(text):
  text = re.split('([\s,;()]+)', text)
  separator = ''

  for n, string in enumerate(text):
      text[n] = list(text[n])
      text[n].reverse()
      text[n] = separator.join(text[n])

  text = separator.join(text)

  return text


import re
def reverse_words(text):
    return ' '.join([x[::-1] for x in text.split(' ')])

def reverse_words(text):

    rev=text[::-1]
    lst_rev=rev.split(' ')
    lst=lst_rev[::-1]
    str=' '.join(lst)
    return str

def reverse_words(text):
  #go for it
  word = ''
  rev_word = ''
  for i in range(0,len(text)):
      if(text[i] != ' '):
          word = word + text[i]
      else:
              rev_word = rev_word + word[::-1] + text[i]
              word = ''
  return(rev_word + word[::-1])

def reverse_words(text):
  return ' '.join(e[::-1] for e in text.split(' '))

def reverse_words(text):
  #go for it
  return " ".join(x[::-1] for x in text.split(" "))

def reverse_words(text):
    return ' '.join(word[::-1] for word in text.split(' '))

def reverse_words(s):
    return ' '.join(x[::-1] for x in s.split(" "))

def reverse_words(str):
    lst = str.split(" ")
    for i in range(len(lst)):
        lst[i] = lst[i][::-1]
    return ' '.join(lst)


def reverse_words(str):
    return ' '.join(x[::-1] for x in str.split(" "))

def reverse_words(str):
  return ' '.join(map(lambda x: x[::-1], str.split(' ')))

def reverse_words(text):

    return ' '.join((text[::-1]).split(' ')[::-1])
    
    """
    rev=text[::-1]
    lst_rev=rev.split(' ')
    lst=lst_rev[::-1]
    str=' '.join(lst)
    return str
    """

def reverse_words(text):
  #go for it
    return ' '.join([i[::-1] for i in text.split(' ')])


def reverse_words (string): 
    string = string[::-1] 
    word_r = string.split(' ')
    word_r.reverse()
    output = ' '.join(word_r)
    return output

def reverse_words(text):
    
    new_text = ""
    
    for word in text.split(" "):
    
        new_text += (word[::-1] + " ")
        
    final = new_text[:-1]

    return final

import re

def reverse_words(text):
    return re.sub(r'([^ ]+)', lambda x: x.group()[::-1], text)

def reverse_words(text):
   return " ".join(["".join(reversed(list(i))) for i in text.split(" ")])

def reverse_words(text):
  text  = text.split(' ')
  re = [i[::-1] for i in text]
  return ' '.join(re)

def reverse_words(text):
    text = text.replace(" ", "\n<SP>\n").lstrip("\n").split("\n") 
    output = []
    for word in text:
        if word != "<SP>":output.append(word[::-1])
        else:output.append(word)
    return str("".join(output)).replace("<SP>"," ")


def reverse_words(text):
    return ' '.join(i[::-1] for i in text.split(' '))

def reverse_words(str):
    ss=list("".join(i[::-1] for i in str.split())[::-1])
    return "".join([ss.pop() if el!=" " else " " for el in str])

def reverse_words(str):
    def reverser(word):
        if word == "":
            return word
        else:
            return reverser(word[1:]) + word[0]
    
    words_list = [reverser(x) for x in str.split(" ")]
    return " ".join(words_list)


reverse_words = lambda x: ' '.join([y[::-1] for y in x.split(' ')])

def reverse_words(st):
  return " ".join("".join(reversed(wr)) for wr in st.split(' '))

import re
reverse_words = lambda s: ''.join([i[::-1] for i in re.split(r'(\s+)', s)]) 

def reverse_words(str):
  return " ".join([st[::-1] for st in str.split(" ")])

def reverse_words(str):
    return ' '.join(item[::-1] for item in str.split(' '))

reverse_words = lambda str: ' '.join(''.join(j for j in i[::-1]) for i in str.split(' '))

def reverse_words(text):
    new_string=""
    text = text.split(" ")
    print (text)
    first = True 
    for word in text:
        if first == True:
            first = False
        else:
            new_string = new_string+" "
        x=len(word)
        for letter in word: 
            new_letter = word[x-1]
            new_string=new_string+new_letter
            x-=1
    return new_string



def reverse_words(text):
    finalWord = ' '
    newWord = text.split(' ')
    for word in newWord:
        word = word[::-1]
        finalWord = finalWord + word + ' '
    return finalWord.strip()

def reverse_words(text):
    #go for it
    #print(text[::-1])
    return " ".join([ word[::-1] for word in text.split(" ")] )

def reverse_words(text):
    text = text.split(' ')
    str = ''
    for i in text:
        i = i[::-1]
        str =str + ' '  + i
    return str[1:]


def reverse_words(text):
    output = ""
    word = ""
    for i in text:
        if i != " ":
            word += i
        else:
            output += word[::-1]
            output += i
            word = ""
    output += word[::-1]
    return output

def reverse_words(text):
    if len(text.split('  ')) > 1:
        return '  '.join([''.join(reversed(t)) for t in text.split('  ')])
    else:
        return ' '.join([''.join(reversed(t)) for t in text.split(' ')])

def reverse_words(text):
    txt_lst = text.split(" ")
    res = []
    for item in txt_lst:
        res.append(item[::-1])
    return " ".join(res)

def reverse_words(text):
    lst = text.split(" ")
    lst = [i[::-1] for i in lst]
    return " ".join(lst)

import re
def reverse_words(text):
  #go for it
    #split the string by spaces
    arr = re.split(r'(\s+)', text)
    # see the array
    #for loop to reverse each string within the array
    reverse = [i[::-1]for i in arr]
    finished = ''.join(reverse)
    return finished


def reverse_words(text):
    textArray = text.split(" ")
    reversedArray = []
    for word in textArray:
        reversedWord = ''
        for letter in word:
            reversedWord = letter + reversedWord
        reversedArray.append(reversedWord)
        
    return " ".join(reversedArray)


def reverse_words(text):
    # Split ' ' will respect multiple whitespace where split() will not.
    return ' '.join(word[::-1] for word in text.split(' '))

def reverse_words(text):
    new_list = text.split(' ')
    lc = [ x[::-1]for x in new_list]
    return(' '.join(lc))
  #go for it


import functools
def reverse_words(text):
    reversed_text = list(functools.reduce(
        lambda acc,st: acc + st, [''.join(reversed(word)) for word in text.split()], ''))
    return_arr = []
    for ch in text:
        if ch.isspace():
            return_arr.append(" ")
        else:
            return_arr.append(reversed_text.pop(0))
    return ''.join(return_arr)


def reverse_words(text: str) -> str:
    # go for it
    final: str = ''
    string_list: list = text.split(' ')
    for i in string_list[:-1]: #go on each word and reverse before last one
        final += i[::-1] + ' ' #add space where needed
    final += string_list[-1][::-1] #add the last word reversed
    return final

def reverse_words(text): 
    return " ".join(word[::-1] for word in text.split(" ")) 
  

text =("")
print(reverse_words(text))     

def reverse_words(text):
  # Splitting the Sentence into list of words. 
    words = text.split(" ") 
      
    # Reversing each word and creating 
    # a new list of words 
    # List Comprehension Technique 
    newWords = [word[::-1] for word in words] 
      
    # Joining the new list of words 
    # to for a new Sentence 
    print(newWords)
    newSentence = " ".join(newWords) 
    
    return newSentence 

def reverse_words(text):
    words = text.split(' ')
    new_text = ''
    
    for word in words:
        new_text += word[::-1]
        
        if word is not words[-1]:
            new_text += ' '
    
    return new_text

def reverse_words(text):
    text = text.split(" ")
    return " ".join([text[i][::-1] for i in range(len(text))])

def reverse_words(text):
    l = [i[::-1] for i in text.split(" ")]
    return " ".join(l)


def reverse_words(text):
# change string to list of words with split
# reverse each word
# concatenate the words back together and return

    lis = text.split(" ")
    reversed_words = []
    new_sentence = ""
    for word in lis:
        new_word = word[::-1]
        print(new_word)
        reversed_words.append(new_word)
    for word in reversed_words:
      new_sentence += word + " "
    return new_sentence[0:len(new_sentence)-1]
    


def reverse_words(text):
    ret_text = ''
    text_list = text.split(' ')
    
    for n, i in enumerate(text_list):
        text_list[n] = i[::-1]
    
    for n, i in enumerate(text_list):
        if n != len(text_list) - 1:
            ret_text += f'{i} '
        else:
            ret_text += i
            
    return ret_text

import re

def reverse_words(text):
    list = re.split(r'(\s+)', text)
    res = ""
    for w in list:
        for i in range(len(w), 0, -1):
            res += w[i - 1]
    return res

def reverse_words(text):
   words=text.split(" ")
   reversed_t=" ".join(reversed(words))
   return reversed_t[::-1]
  #go for it


import re

def reverse_words(text):
    wordList = re.findall("\S+", text)
    spaceList = re.findall("\s+", text)
    answerList = []
    answerString = ""
    spaceCounter = 0
    for word in wordList:
        answerList.append(word[::-1])
        if spaceCounter < len(spaceList):
            answerList.append(spaceList[spaceCounter])
            spaceCounter += 1
    return(answerString.join(answerList))

def reverse_words(text):
    words = text.split(' ')
    backwards = []
    for word in words:
        backword = ''
        for c in range(len(word)-1, -1, -1):
            backword += word[c]
        backwards.append(backword)
    return ' '.join(backwards)

def reverse_words(text):
  #go for it
    n = len(text)
    liste = text.split(" ")
    liste = [reverse(mot) for mot in liste]
    return " ".join(liste)
    
def reverse(text):
    n = len(text)
    reponse = ""
    for i in range(n):
        reponse += text[n - (i+1)]
    return reponse

def reverse_words(text):
    reverse=''
    for word in text.split(' ')[:-1]:
        reverse+=word[::-1]+' '
    return reverse+text.split(' ')[-1][::-1]

def reverse_words(text):
    print(text)
    a = list(enumerate(text))
    new_list = []
    new_list2 = []
    x = text.split()
    for el in x:
        new_list.append(list(reversed(el)))
    for el in new_list:
        y = "".join(el)
        new_list2.append(y)
    new_list3 = [i for ele in new_list2 for i in ele]
    for el in a:
        if el[1] == " ":
            new_list3.insert(el[0], " ")
    z = "".join(new_list3)

    return z

def reverse_words(text):
    array = text.split(' ')
    new_array = [ word[::-1] for word in array]
    return ' '.join(new_array)
  


def reverse_words(text):
    medzera = ' '
    x = text.split(medzera)
    for i in range(len(x)):
        x[i] = x[i][::-1]
    y = medzera.join(x)
    return y


def reverse_words(text):
    ls = []
    
    for i in text.split():
        ls.append(i[::-1])

    if text.find("  ") > -1:
        return "  ".join(ls)
    else:
        return " ".join(ls)

def reverse_words(text):
    t = text.split()
    t_new = []
    for i in t:
        i = i[::-1]
        t_new.append(i)
    sp1 = " ".join(t_new)
    if len(sp1) != len(text):
        sp2 = "  ".join(t_new)
        return sp2
    else:
        return sp1

def reverse_words(text):
    spaces = text.count('  ')
    text = [x[::-1] for x in text.split()]
    return '  '.join(text) if spaces >= 1 else ' '.join(text)

def reverse_words(text):
    return ' '.join([''.join(list(i)[::-1]) for i in text.split(' ')])


def reverse_words(text):
    split_txt = text.split(" ")  
    
    result = ""
    
    for word in split_txt:
        
        result += "".join(word[::-1]) + " "
        
    print((result[:-1]))
    return(result[:-1])


def reverse_words(text):
    text_split = text.split(" ")
    index = 0
    for t in text_split:
        text_split[index] = "".join(reversed(t))
        index += 1
    
    return (" ".join(text_split))

import re
def reverse_words(text):
    stuff=re.split('(\s+)', text)
    print (stuff)
    cat=list()
    for words in stuff:
        reverse=words[::-1]
        cat.append(reverse)
    dog=''.join(cat)

    return dog

  #go for it


def reverse_words(text):
  #go for it
    t_list = text.split(' ')
    for i, t_ele in enumerate(t_list):
        if t_ele == '':
            t_list[i] = t_ele
        else:
            t_list[i] = t_ele[::-1]
    return ' '.join(t_list)

import re

def reverse_words(text):
    li_text = re.split("( )",text) # Why must regular split be different from regex split :/
    solution = ''.join(list(word[::-1] for word in li_text)) # Separated from split for readability.
    
    return solution

def reverse_words(text):
    split_text = text.split()
    sentence_list = []
    for word in split_text:
        reverseword_list = []
        for i in word:
            reverseword_list.append(i)
        sentence_list.append("".join(reverseword_list[::-1]))
    for i in range(len(text)-1):
        if text[i] == " " and text[i+1] == " ":
            return ("  ".join(sentence_list))
        if text[i] == " " and text[i+1] != " ":
            pass
    return (" ".join(sentence_list))



def reverse_words(text):
    a = text.split(" ")
    b = []
    for word in a: 
        b.append(word[::-1])
    c = ' '.join(b)
    return(c)
        
    
        


def reverse_words(text):
    backwards = (text[::-1]).split(" ")
    text = ""
    print(backwards)
    for word in backwards[::-1]:
        text +=word
        text +=" "
  
    return text[:-1]

def reverse_words(text):
    a = text
    list_1 = []
    list_3 = []
    split = text.split(' ')
    for x in split:
        list_2 = []
        if x == "":
            list_3.append(x)
        else:
            length = len(x)
            for y in range(length-1, -1, -1):
                list_2.append(x[y])
            final = ''.join(list_2)
            list_3.append(final)
    re_final = ' '.join(list_3)
    return re_final


def reverse_words(text):
    reversed = ""
    for word in text.split(" "):
        w =" "
        for char in word:
            w = char + w
        reversed = reversed + w
    return (reversed.strip())

def reverse_words(text):
    r = []
    for w in text.split(' '):
        r.append(w[int(len(w))::-1])
    s = ' '
    return s.join(r)


def reverse_words(text):
    w=text.split(" ")
    s=""
    for i in w:
        x=i[::-1]
        if s =="":
            s=x
        else:
            s=s+" "+x
    return s


def reverse_words(text):
    s = ' '.join([i[::-1] for i in text.split(' ')])
    return s


def reverse_words(text):
    text = text.split(' ')
    text = [x[::-1] for x in text]
    return ' '.join(text)

def reverse_words(text):
    word_list = text.split()
    reversed_str = ''
    spacer = ''
    if ' ' in text:
        count = 1
        spacer += ' '
        index = text.find(' ')
        while text[index + count] == ' ':
            spacer += ' '
            count += 1
            
    for item in word_list:
        item = item[::-1]
        if len(reversed_str) < 1:
            reversed_str += item
        else:
            reversed_str += (spacer + item)
    return reversed_str

def reverse_words(text):
    tempWord = ""
    result = ""
    for i in range(len(text)):
        if text[i] != " ":
            tempWord += text[i]
            if i == len(text)-1:
                result += tempWord[::-1]
        else:
            if text[i-1] != " ":
                result += tempWord[::-1] + " "
                tempWord = ""
            else:
                result += " "
    return result

def reverse_words(text):
    final_string = ""
    for i in ([i[::-1] for i in text.split(" ")]):
        final_string += (i + " ")
    return final_string[:-1]

def reverse_words(text):
    #go for it
    reversed_string = []
    for i in text.split(' '):
        reversed_string.append(i[::-1])
    return ' '.join(reversed_string)

def reverse_words(text):
    res = list()
    win = str(text).split()
    for w in win:
        word = str()
        for l in w:
            word = l + word
        res.append(word)
    if '  ' in text:
        return '  '.join(res)
    else:
        return ' '.join(res)
    
  #go for it


def reverse_words(text):
  #go for it
    string = text.split(' ')
    for i,j in enumerate(string):
        string[i] = j[::-1]
    return ' '.join(string)


def reverse_words(text):
  #go for it
    spl = text.split(" ")
    new = ''
    for i in spl:
        new+=i[::-1]+" "
    return new.strip()

def reverse_words(text):
    arr=text.split(" ")
    resarr=[]
    t=" "
    for i in arr:
        a=[]
        s=""
        for j in i:            
            a.insert(0,j)
        resarr.append(s.join(a))
    return t.join(resarr)   
        
  #go for it


def reverse_words(text):
  #go for it
    textlist = text.split(' ')
    textlist = map(lambda x:x[::-1],textlist)
    return ' '.join(textlist)

def reverse_words(text):
    words = text.split()
    for i in range(len(words)):
        words[i] = words[i][::-1]
    if '  ' in text:
        return "  ".join(words)
    return " ".join(words)

def reverse_words(text):
    new=text.split(' ')
    for elem,text in enumerate(new):
        new[elem]=text[::-1]
    return ' '.join(new)