I'm trying to figure out something that seems like it should be simple. I'm trying to remove the middle initial from names, but I'm not sure how to do it without making a replace() for every letter of the alphabet. This is what I'm looking for:
(Starts as)
"John D Smith"
"Robert B Johnson"
(Ends as)
"John Smith"
"Robert Johnson"
What is the simplest way of accomplishing the above in Python? The middle initial is random, but is always surrounded by white space.
May this help, based on your post
>>> import re
>>> re.sub(' [A-Z]* ', ' ', "John D Smith")
'John Smith'
>>> re.sub(' [A-Z]* ', ' ', "Robert B Johnson")
'Robert Johnson'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With