简体   繁体   中英

How do I create lists in a list in Python? Is it possible?

How to make list each character of list? like this:

li = ['A','B','C']

into:

li = [['A'],['B'],['C']]

See "list comprehension".

It is simply,

[[i] for i in i]

or more generally,

[f(x) for x in list_name]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM