In this post we need to enter the string at the beginning of all items in a list.
For ex: We're given string = "Tutorials_Point" and List contains multiple element such as "1", "2" etc. So in this we need to add Tutorials_Point in front of "1", "2" and so on.
Example
Aproach 1
sample_list = [1, 2, 3] print(['Tutorials_Point{0}'.format(i) for i in sample_list])
Output
//['Tutorials_Point1', 'Tutorials_Point2', 'Tutorials_Point3']
Approach 2
sample_list = [1, 2, 3] sample_str = 'Tutorials_Point' sample_str += '{0}' sample_list = ((map(sample_str.format, sample_list))) print(sample_list)
Output
//['Tutorials_Point1', 'Tutorials_Point2', 'Tutorials_Point3']