0

I mean something like this;

        input:    x = 12345
        code:     y = magic(x)
              print(y)
        output:   (1, 2, 3, 4, 5)

I want to split the long interger in to many 1 length integers and put them in a list. Hopefully you guys can help

jeff
  • 1
  • 1

1 Answers1

0

Quoted from https://www.geeksforgeeks.org/python-split-string-into-list-of-characters/

Solution #1: Using For loop

This approach uses for loop to convert each character into a list. Just enclosing the For loop within square brackets [] will split the characters of word into list.

def split(word): 
    return [char for char in word]  

word = 'geeks'
print(split(word))

Output:

['g', 'e', 'e', 'k', 's']

Solution #2: Typecasting to list

Python provides direct typecasting of string into list using list()

def split(word): 
    return list(word) 

word = 'geeks'
print(split(word))

Output:

['g', 'e', 'e', 'k', 's']
henriquehbr
  • 1,063
  • 4
  • 20
  • 41