Python | Split a list that has a single integer



Examples :

  Input:  Input = [23]  Output:  Output = [2, 3]  Input:  Input = [15478]  Output:  Output = [1, 5, 4, 7, 8] 

Method # 1: Using cards

# Python code to split a list containing a single integer

  
# Initialization list

input = [ 200 ]

 
# Using the map

output = list ( m ap ( int , str ( input [ 0 ])))

 
# Printout

print (output)

Exit:

 [2, 0, 0] 

Method # 2: Using List Comprehension

# Python code to split the list, containing one integer

 
# Initialization list

input = [ 231 ]

  
# Using the comprehension list

output = [ int (x) if x.isdigit () else

  for z in input for x in str (z)]

 
# Printout

print ( output)

Exit:

 [ 2, 3, 1] 

Method # 3: Using Loops

# Python code to split the list containing one integer

 
# Initialization list

input = [ 987 ]

  
# Convert to int

input = int ( input [ 0 ])

  
# Initialize the output list

output = []

 

while input & gt; 0 :

  rem = input % 10

input = int ( input / 10 )

output.append (re m)

 
# Printout

print (output)

Exit:

 [7, 8, 9]