0
import re


# initializing list
test_list = ["gfgBest", "forGeeks", "andComputerScience"]
 
# printing original list
print("The original list : " + str(test_list))
 
# using regex() to perform task
res = [re.sub(r"(\w)([A-Z])", r"\1 \2", ele) for ele in test_list]
 
# printing result
print("The space added list of strings : " + str(res))
trincot
  • 317,000
  • 35
  • 244
  • 286
skittels
  • 11
  • 1
  • Those are backreferences. – trincot Feb 03 '22 at 15:54
  • Please [edit] your question to actually ask a question inside it, and keep the title a short summary of your problem. And please elaborate on the question, what part of `r"\1 \2"` are you wondering about? – Some programmer dude Feb 03 '22 at 15:55
  • Also please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Feb 03 '22 at 15:55
  • The question "what's the reason" is extremely vague. Are you asking 1) what it means, 2) why it's used in this particular case, 3) something else? – bereal Feb 03 '22 at 15:58
  • I meant to ask what it means – skittels Feb 03 '22 at 18:05

0 Answers0