Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a list with elements to list with list with only one element?

Tags:

python

I have a list with n elements but i would like to convert it to a list which contains n list, and every list contains a single element.

 a = ['1','2','3','4']
 b = [['1'],['2'],['3'],['4']]

How can I make from a to b?

like image 416
tmsblgh Avatar asked Nov 17 '25 12:11

tmsblgh


1 Answers

You can try list comprehension

b = [[i] for i in a]
like image 58
JRodDynamite Avatar answered Nov 19 '25 02:11

JRodDynamite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!