How to split list based on characters and then make sub-lists?

Question:

How do I split a list into sub-lists, and then further split that to make each character an independent value?

I need to do this all inside of Python, version 3.6.5. The list will be in integers.

I need to convert

[123, 456]

into

[[1,2,3], [4,5,6]]

EDIT:

And after I have done that, how do I print the first character of the first sublist?

Note: Splitting integer in Python? and Turn a single number into single digits Python don’t solve or answer my problem, as they do not explain how to make sub-lists out of them.

Answers:

For example, using list comprehension:-

my_list = ['123', '456']
[list(x) for x in my_list]

If my_list is a list of integers:-

my_list = [123, 456]
[[int(x) for x in str(n)] for n in my_list]
Answered By: Tom Ron

A simple list comprehension will do, the idea is iterate over the characters in the string representation of the numbers:

[[int(x) for x in str(s)] for s in l]
Answered By: Netwave
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.