在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] ]
答案 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']]