Given a list of string, write a Python program to Insert some letter after each k letters in given list of strings.
As we know inserting element in a list is quite common, but sometimes we need to operate on list of strings by considering each letter and insert some repeated elements some fixed frequency. Let’s see how to achieve this task using Python.
Method #1: Using enumerate() method
Original list : ['p', 'y', 't', 'h', 'o', 'n'] The lists after insertion : ['p', 'y', 'G', 't', 'h', 'G', 'o', 'n', 'G']
Method #2: Using itertools
Original list : ['p', 'y', 't', 'h', 'o', 'n'] The lists after insertion : ['p', 'y', 't', 'x', 'h', 'o', 'n', 'x']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - Insert character in each duplicate string after every K elements
- Python | Insert after every Nth element in a list
- Python | Ways to sort letters of string alphabetically
- Python | First N letters string construction
- Python program to verify that a string only contains letters, numbers, underscores and dashes
- Python Program that Displays the Letters that are in the First String but not in the Second
- Python program to check if lowercase letters exist in a string
- Python program to calculate the number of digits and letters in a string
- Python | Insert list in another list
- Python | Insert the string at the beginning of all items in a list
- Python | Insert character after every character pair
- Python | Split given list and insert in excel file
- Python regex to find sequences of one upper case letter followed by lower case letters
- Python | Remove all characters except letters and numbers
- Regex in Python to put spaces between words starting with capital letters
- Python Program that Displays Letters that are not common in two strings
- Python | Convert List of String List to String List
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Sort each String in String list
- Python - Remove front K characters from each string in String List
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.