Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- test = "I love python3 programming and my email-id is abc@gmail.com"
- newstr = ""
- y = re.split(r"[\s@.]+", test) ##splits into a list of words by regual expresion.
- x = re.findall(r"[\s@.]+", test)## splits into list of special characters by regualr expression.
- for i in range(len(x)):
- if x[i] != " ": ##makes sure the character is not a space
- y[i] = x[i]+y[i] ##fixes the words to add symbols to the start of the word "abc@" -> "@abc". It becomes correct after reversing "@abc" -> "cba@".
- for word in y:
- for i in range(len(word)): ##for character in word
- newstr += (word[len(word)-i-1:len(word)-i]) ##reverse the order of the characters using substrings
- if r"".join(re.split(r"[\w']+", newstr[-1:])) == "": #if the last letter of the line is not a symbol add a space.
- newstr += " "
- print(newstr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement