emails = ['[email protected]',
'[email protected]',
'[email protected]',
'[email protected]']
a = []
for email in emails:
a = email.replace('.',' ').split('@')
Print(a)
here is all I can do so far. I am new to this. is there any way I can create a function that automatically separate name and email while printing output such as 'Mr T works at Ateam'. thank you
CodePudding user response:
The following functions are used here: find to find the index of the first character from left to right, rfind to search from right to left, capitalize to set the first capital letter.
Index slices are used to extract the desired part of the string. At the end, all the parts are connected . The string is printed out at each iteration. An array of these strings is also created and printed. If the answer helped you, then you can vote for it.
emails = ['[email protected]',
'[email protected]',
'[email protected]',
'[email protected]']
a = []
work = "works at"
for email in emails:
ind_p = email.find('.')
ind_a = email.find('@')
ind_sp = email.rfind('.')
qqq = email[:ind_p].capitalize() " " email[ind_p 1:ind_a].capitalize() " " work " " email[ind_a 1:ind_sp].capitalize()
print(qqq)
a.append(qqq)
print(a)
Output
Mr T works at Ateam
Baby Spice works at Spicegirls
Scary Spice works at Spicegirls
Kermit Frog works at Muppets
['Mr T works at Ateam', 'Baby Spice works at Spicegirls', 'Scary Spice works at Spicegirls', 'Kermit Frog works at Muppets']