Python | Split a list having single integer
Given a list containing single integer, the task is to split each value in the list.
Examples:
Input: Input = [23] Output: Output = [2, 3] Input: Input = [15478] Output: Output = [1, 5, 4, 7, 8]
Method #1 : Using Map
# Python code to split list containing single integer # List initialization input = [200] # Using map output = list(map(int, str(input[0]))) # Printing output print(output) |
chevron_right
filter_none
Output:
[2, 0, 0]
Method #2 : Using list comprehension
# Python code to split list containing single integer # List initialization input = [231] # Using list comprehension output = [int(x) if x.isdigit() else x for z in input for x in str(z)] # Printing output print(output) |
chevron_right
filter_none
Output:
[2, 3, 1]
Method #3 : Using Loops
# Python code to split list containing single integer # List initialization input = [987] # Converting to int input = int(input[0]) # Output list initialization output = [] while input>0: rem = input % 10 input = int(input / 10) output.append(rem) # Printing output print(output) |
chevron_right
filter_none
Output:
[7, 8, 9]
Recommended Posts:
- Python | Convert a list of multiple integers into a single integer
- Python | Pandas Split strings into two List/Columns using str.split()
- Python | Custom list split
- Python | Split list into lists by particular value
- Python | Convert list of string into sorted list of integer
- Python | Split a list into sublists of given lengths
- Python | Split string into list of characters
- Python | Split nested list into two lists
- Python | Associating a single value with all list items
- Python | Split given list and insert in excel file
- Python | Split strings in list with same prefix in all elements
- Python | Split dictionary of lists to list of dictionaries
- Python | Split list of strings into sublists based on length
- Python | Pandas Reverse split strings into two List/Columns using str.rsplit()
- Python | Binary list to integer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



