I have a list of names of apple products in random format.
like take a single product name iphone 11 pro
which can be found
Iphone 11 Pro
or iphone 11 Pro
, or anything that can be.
But i want to change this to the naming pattern how the apple gives them, eg : iPhone 11 Pro
So, I'm trying to change all of then first to title and then replacing first two characters of the string. but problem is second part is not working. Being a beginner im not able to reproduce the solution. I have read the article about regex in python. but unable to find better way to do it.
Thats how im trying..
names = ['Iphone 12', 'iphone 11 pro', 'IPad pro', 'Imac pro']
titled_names = []
updated_names = []
# first change all to title
for i in names:
i.title()
titled_names.append(i)
# replace the first two char
for i in titled_names:
i.replace('Ip', 'iP', 1)
updated_names.append(i)
print(updated_names)
But this should not supposed to work in anyway as there can some products where first char wont be Ip, like in the Imac. the end result of the names list should be like this.
names = ['iPhone 12', 'iPhone 11 Pro', 'iPad Pro', 'iMac Pro']
so how can I achieve this. first char small second capital in first letter, and rest in Title Case