Convert list into list of lists

前端 未结 3 1315
攒了一身酷
攒了一身酷 2020-11-29 08:52

I want to convert list into list of list. Example:

my_list = [\'banana\', \'mango\', \'apple\']

I want:

my_list = [[\'banan         


        
3条回答
  •  执念已碎
    2020-11-29 09:20

        lst = ['banana', 'mango', 'apple']
        lst_of_lst = []
        for i in lst:
            spl = i.split(',')
            lst_of_lst.append(spl)
        print(lst_of_lst)
    

    first create an empty list and then iterate through your list. split each list and append them to your empty list.

提交回复
热议问题