0
How to add item from a list to a list
a = [["line1", "arc1", "line2", "line3", "line4", "line5"], ["line6", "arc2", "line7"]] b = ["Layer1", "Layer2"] # result need to be: c = [["Layer1", "line1", "arc1", "line2", "line3", "line4", "line5"],["Layer2", "line6", "arc2", "line7"]]
7 Answers
+ 5
probably not the best solution but it works:
a = [["line1", "arc1", "line2"], ["line3", "arc2", "line4"]]
b = ["Layer1", "Layer2"]
c = []
d = []
res = []
c.append(b[0])
c.extend(a[0])
d.append(b[1])
d.extend(a[1])
res.append(c)
res.append(d)
print(res)
# output: [['Layer1', 'line1', 'arc1', 'line2'], ['Layer2', 'line3', 'arc2', 'line4']]
# result need to be:
c = [["Layer1", "line1", "arc1", "line2"],["Layer2", "line3", "arc2", "line4"]]
if you really need to have doublequotes around string you can use replace to do this
+ 1
a[0].insert(0, b[0])
a[1].insert(0, b[1])
Assuming you are using Python...
+ 1
Yep. Thats what I was talking about using for loop, Eddy Lucas
0
You can even use a for loop
0
Thnx Tomas.
Yes it's pyton.
The lists a and b vary in length in runtime
0
Thnx for helping Thomas
I tried this:
for x in range(len(b)):
a[x].insert(0, b[x])
print(a)
0
~ swim ~ I'll try when im at work in about 3 weeks
BTW the lists are a random nr of lines and or arcs. But are always a group or groups on a layer or layers