-4
Neriman KivrakCanan AcerTurkiye El MohammedAyse Ozgecan

becomes

Neriman Kivrak, Canan Acer, Turkiye El Mohammed, Ayse Ozgecan
Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
  • Welcome to SO, you have to provide some proof of effort, please, take a look at https://stackoverflow.com/help/how-to-ask – Gamopo Apr 06 '21 at 11:39

1 Answers1

0

Assuming you wanted the output as one string, here is a solution:

import re

string = 'Neriman KivrakCanan AcerTurkiye El MohammedAyse Ozgecan'

#Splits each "word" into item in a list
y = string.split()

names = []

#Splits joined surname and first name
for word in y:
  z = re.findall('[A-Z][^A-Z]*', word)
  names.append(z)

new_string = ''

#Creates string combining first names with respective surnames
for name in names:
  if len(name) == 1:
    new_string += ' {}'.format(name[0])
  elif len(name) >= 2:
    new_string += ' {}, {}'.format(name[0], name[1])

#Result
print(new_string)
#Output: Neriman Kivrak, Canan Acer, Turkiye El Mohammed, Ayse Ozgecan
LWHR
  • 71
  • 4
  • @boratutumluer no worries. Please upvote the answer and accept it if you found it helpful – LWHR Apr 06 '21 at 13:37