
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Insert the string at the beginning of all items in a list in Python
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']
- Related Articles
- Python program to insert a new node at the beginning of the Circular Linked List
- Python program to insert a new node at the beginning of the Doubly Linked list
- Write a program in C++ to insert a Node at the beginning of the given Singly linked list
- How to insert a text at the beginning of a file in Linux?
- How to insert a string in beginning of another string in java?
- Program to find minimum value to insert at beginning for all positive prefix sums in Python
- How to insert text at the beginning of the text box in Tkinter?
- Align flex items at the beginning of the container with CSS
- How to match at the beginning of string in python using Regular Expression?
- Associating a single value with all list items in Python
- Insertion at the beginning in OrderedDict using Python
- How to randomize the items of a list in Python?
- Python program to insert a new node at the end of the Circular Linked List
- Python program to insert a new node at the middle of the Circular Linked List
- Python program to insert a new node at the end of the Doubly Linked List

Advertisements