Home > Enterprise >  swap name and surename with that is spaced with ,
swap name and surename with that is spaced with ,

Time:11-01

I am fetching names from tags in wikipedia like this:

k = BeautifulSoup(str(Position),"html.parser")         
name = k.find('a')['title']

names in this case will result in this

'Bassey, Charles'

Is there a way I can convert the names that are spaced like this to this:

'Charles Bassey'

CodePudding user response:

last_first = 'Bassey, Charles'
last_name,first_name  = last_first.split(',')
fullname = f'{first_name},{last_name}'
print(fullname)

output

Charles,Bassey
  • Related