我在 python 的另一个列表中添加一个列表。
a = [ 1, 2, 3, 'a', 'aa']
a.insert(3, ['b','a'])
print a
输出:
[1, 2, 3, ['b', 'a'], 'a', 'aa']
期望的输出:
[1, 2, 3,'b', 'a', 'a', 'aa']
我希望输出是单个列表,而不是列表的层次结构。在这种情况下我该怎么办?
后续问题
total = []
tname = temp_list[0]
if (tname == 'order'):
total[0:0] = temp_list
else:
total[10:10] = temp_list
输入是一个 json(复制一个子集):
["order", "7", "39136", "O", "252004.18", "1996-01-10", "2-HIGH", "Clerk#000000470", "0", "ly special requests "]
["order", "32", "130057", "O", "208660.75", "1995-07-16", "2-HIGH", "Clerk#000000616", "0", "ise blithely bold, regular requests. quickly unusual dep"]
["line_item", "1", "155190", "7706", "1", "17", "21168.23", "0.04", "0.02", "N", "O", "1996-03-13", "1996-02-12", "1996-03-22", "DELIVER IN PERSON", "TRUCK", "egular courts above the"]
["line_item", "1", "67310", "7311", "2", "36", "45983.16", "0.09", "0.06", "N", "O", "1996-04-12", "1996-02-28", "1996-04-20", "TAKE BACK RETURN", "MAIL", "ly final dependencies: slyly bold "]
输出(子集):
[["order", "7", "39136", "O", "252004.18", "1996-01-10", "2-HIGH", "Clerk#000000470", "0", "ly special requests "], ["line_item", "7", "182052", "9607", "1", "12", "13608.60", "0.07", "0.03", "N", "O", "1996-05-07", "1996-03-13", "1996-06-03", "TAKE BACK RETURN", "FOB", "ss pinto beans wake against th"], ["line_item", "7", "145243", "7758", "2", "9", "11594.16", "0.08", "0.08", "N", "O", "1996-02-01", "1996-03-02", "1996-02-19", "TAKE BACK RETURN", "SHIP", "es. instructions"], ["line_item", "7", "94780", "9799", "3", "46", "81639.88", "0.10", "0.07", "N", "O", "1996-01-15", "1996-03-27", "1996-02-03", "COLLECT COD", "MAIL", " unusual reques"], ["line_item", "7", "163073", "3074", "4", "28", "31809.96", "0.03", "0.04", "N", "O", "1996-03-21", "1996-04-08", "1996-04-20", "NONE", "FOB", ". slyly special requests haggl"], ["line_item", "7", "151894", "9440", "5", "38", "73943.82", "0.08", "0.01", "N", "O", "1996-02-11", "1996-02-24", "1996-02-18", "DELIVER IN PERSON", "TRUCK", "ns haggle carefully ironic deposits. bl"], ["line_item", "7", "79251", "1759", "6", "35", "43058.75", "0.06", "0.03", "N", "O", "1996-01-16", "1996-02-23", "1996-01-22", "TAKE BACK RETURN", "FOB", "jole. excuses wake carefully alongside of "], ["line_item", "7", "157238", "2269", "7", "5", "6476.15", "0.04", "0.02", "N", "O", "1996-02-10", "1996-03-26", "1996-02-13", "NONE", "FOB", "ithely regula"]]
这给了我一个父列表中的多个列表,而不是单个列表的预期输出。知道是什么原因吗?