У меня есть следующий список (генерируется после последовательности вычислений других функций):
[1, 0, 2]
[1, 0, 2]
[0]
[1]
[2]
[1, 0, 2]
[0]
[1]
[2]
[1, 2, 0]
[0, 1]
[2]
[0, 2, 1]
[0, 1, 2]
[0, 1, 2]
[2, 0]
[1]
[2, 0]
[1]
Я хочу создать плоский список [1, 0, 2, 1, 0, 2, 0, 1, 2, 1, 0, 2, 0, 1, 2, 1, 2, 0, 0, 1, 2, 2, ....]
.Элементы могут повторяться, но имеют неодинаковую длину в конце (0 может быть 10, 1 может быть 30, ...).
Когда я запускаю print([list(i) for i in componentVisited])
, я получаю следующую ошибку:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-466-0a019fbab5b6> in <module>()
84 numVertices=3
85 xs = linspace(xstart, xend, num=xpts)
---> 86 data = graphLargestComponentSize(numVertices, xs)
87 #data[:20]
88
<ipython-input-466-0a019fbab5b6> in graphLargestComponentSize(n, theRange)
72
73 def graphLargestComponentSize(n, theRange):
---> 74 return [(p, sizeOfLargestComponent(randomGraph(n, p))) for p in theRange]
75
76
<ipython-input-466-0a019fbab5b6> in sizeOfLargestComponent(vertices)
68 def sizeOfLargestComponent(vertices):
69
---> 70 return max(len(c) for c in connectedComponents(vertices))
71
72
<ipython-input-466-0a019fbab5b6> in connectedComponents(vertices)
42 components.append(componentVisited)
43 cumulativeVisited |= componentVisited
---> 44 print([list(i) for i in componentVisited])
45 from itertools import chain
46 newlist=[i for i in componentVisited]
TypeError: iteration over non-sequence
Любая помощь в разгадке этой загадки была бы великолепной.