Вы можете попробовать с join
и после сопоставления с list.map
строку с вашей пользовательской функцией:
import string
doc = ['This is the first string', 'This is the second string' ,'This is the third string']
def edittext(t):
t = t.upper()
return t
edited_doc=[]
for i,val in enumerate(doc):
edited_doc.append('string'+string.ascii_lowercase[i])
edited_doc.append(' '.join(map(edittext,val.split())))
print(edited_doc)
Вывод:
['stringa', 'THIS IS THE FIRST STRING', 'stringb', 'THIS IS THE SECOND STRING', 'stringc', 'THIS IS THE THIRD STRING']
Также в качестве предложения и, как сказал @Muhammadrasul, вы назначаете пары (ключ, значение), поэтому вы можете рассмотреть возможность использования словаря:
import string
doc = ['This is the first string', 'This is the second string' ,'This is the third string']
def edittext(t):
t = t.upper()
return t
edited_dict={'string'+string.ascii_lowercase[i]:' '.join(map(edittext,val.split())) for i,val in enumerate(doc)}
print(edited_dict)
Вывод:
{'stringa': 'THIS IS THE FIRST STRING', 'stringb': 'THIS IS THE SECOND STRING', 'stringc': 'THIS IS THE THIRD STRING'}