のリストに変換する方法をどのように変換します:は、文字列のリストは、リストの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] ]
のリストに変換する方法をどのように変換します:は、文字列のリストは、リストの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] ]
使用リストの内包を。
>>> a = [ 'i am going to America', 'i will come by tomorrow evening' ]
>>> [[x] for x in a]
[['i am going to America'], ['i will come by tomorrow evening']]
あなたはリスト内包表記を使用して、あなたがリストとして各エントリを宣言しmain_list
list = ['i am going']
main_list.append(list)
にそれを追加する必要があり、別のリスト
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']]
を生成することができますが、これを試してみてください。
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']]