Sometimes, while working with Python, we can a problem in which we need to pad strings in lists at trailing or leading position. This kind of problem is quite common and can occur in day-day programming or web development. Let’s discuss a way in which this task can be performed.
Method : Using
+ operator + list comprehension
In this task, we just append the string at rear or front position using + operator and list comprehension is used to iterate through all the elements.
The original list : ['a', 'b', 'c', 'd'] list after prefix addition : ['gfga', 'gfgb', 'gfgc', 'gfgd'] list after suffix addition : ['agfg', 'bgfg', 'cgfg', 'dgfg']
- Python | Perform append at beginning of list
- Python | Remove empty strings from list of strings
- Python | Tokenizing strings in list of strings
- Python | Merge list of tuple into list by joining the strings
- Python | Filter list of strings based on the substring list
- Python | Filter a list based on the given list of strings
- Python | Convert list of strings to list of tuples
- Python | Convert list of tuples to list of strings
- Python | How to sort a list of strings
- Python | Finding strings with given substring in list
- Python | Remove all strings from a list of tuples
- Python | Remove all digits from a list of strings
- Python | Extract numbers from list of strings
- Python | Group strings at particular element in list
- Python | Sort all sublists in given list of strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.