How to append prefix to strings in a list with Python

1 Answer

0 votes
lst = ['python', 'php', 'java', 'c++', 'c']
 
prefix = 'X_'
 
lst = [prefix + s for s in lst]

print(lst)
    

    
'''
run:
     
['X_python', 'X_php', 'X_java', 'X_c++', 'X_c']

'''

 



answered Feb 18, 2023 by avibootz
...