如何将字符串列表转换为列表列表

时间:2017-08-08 06:00:11

标签: python-3.5

在Python中如何转换:

list a = [ 'i am going to America', 'i will come by tomorrow evening' ]

    into

list b = [ [i am going to America], [i will come by tomorrow evening] ]

3 个答案:

答案 0 :(得分:2)

您可以使用列表理解并生成另一个列表

list_a = [ 'i am going to America', 'i will come by tomorrow evening' ]
print(list_a) # ['i am going to America', 'i will come by tomorrow evening']

list_b = [[x] for x in list_a]
print(list_b) # [['i am going to America'], ['i will come by tomorrow evening']]

答案 1 :(得分:1)

使用列表理解。

<user-dir>/.gradle/appengine-sdk/appengine-java-sdk-<version>/bin

答案 2 :(得分:0)

您需要将每个条目声明为列表,然后将其附加到main_list

list = ['i am going']
main_list.append(list)

试试这个:

list = ['iam g', 'here']
 main_list = []
main_list.append(list)
 print main_list
output: [['iam g', 'here']]
 main_list.append(list)
 print main_list
output: [['iam g', 'here'], ['iam g', 'here']]