- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Split Numeric String into K digit integers
When it is required to split a numeric string into K digit integers, a simple iteration, the ‘int’ method and the ‘append’ methods are used.
Below is a demonstration of the same −
my_string = '69426874124863145' print("The string is : " ) print(my_string) K = 4 print("The value of K is ") print(K) my_result =  for index in range(0, len(my_string), K): my_result.append(int(my_string[index : index + K])) print("The resultant list is : ") print(my_result) print("The resultant list after sorting is : ") my_result.sort() print(my_result)
The string is : 69426874124863145 The value of K is 4 The resultant list is : [6942, 6874, 1248, 6314, 5] The resultant list after sorting is : [5, 1248, 6314, 6874, 6942]
A string is defined and is displayed on the console.
The value of K is defined and is displayed on the console.
An empty list is defined.
The list is iterated over, and the elements in the string within a specific range are converted into an integer.
This value is appended to the empty list.
This is displayed as the output on the console.
This list is sorted again and is displayed on the console.
- Python program to split string into k distinct partitions
- Python – Reform K digit elements
- C# program to split the Even and Odd integers into different arrays
- Split string into sentences using regex in PHP
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Extract tuples having K digit elements in Python
- Python – Average of digit greater than K
- Check if given string can be split into four distinct strings in Python
- How to split Python tuples into sub-tuples?
- Split tuple into groups of n in Python
- Python - Split list into all possible tuple pairs
- How to split a Java String into tokens with StringTokenizer?
- How to split a String into an array in Kotlin?