Given a string (be it either string of numbers or characters), write a Python program to split the string by every nth character.
Input : str = "Geeksforgeeks", n = 3 Output : ['Gee', 'ksf', 'oor', 'gee', 'ks'] Input : str = "1234567891234567", n = 4 Output : [1234, 5678, 9123, 4567]
Method #1: Using list comprehension
['Gee', 'ksf', 'org', 'eek', 's']
Method #2: Using
['123G', 'eeks', 'ForG', 'eeks', '4567']
- Python | Split multiple characters from string
- Python | Split string into list of characters
- Python | Split tuple into groups of n
- Python | Split list in uneven groups
- Python | Ways to split strings on Uppercase characters
- Python | Minimum Sum of Consecutive Characters
- Python String | split()
- How to split a string in C/C++, Python and Java?
- Python | K Character Split String
- Python | Split string on Kth Occurrence of Character
- Python | Split given string into equal halves
- Python | String Split including spaces
- Python program to split and join a string
- Split a string in equal parts (grouper in Python)
- Python | Split strings and digits from 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 email@example.com. 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.