Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For example I have a list of:

[[1,1,1], [1,1,0], [1,0,1], [1,0,1], [1,1,1], [1,1,0], [1,0,1], [1,0,1], [1,0,1], [1,1,0]]


I want it to be:

[[1,1,1,1,1,0], [1,0,1,1,0,1], [1,1,1,1,1,0], [1,0,1,1,0,1], [1,0,1,1,1,0]]



If you don't get it here is another example:

[a, b, c, d, e, f, g, h, i, j]

[ab, cd, ef, gh, ij]


What I have tried:

list = [[1, 1, 1], [1, 1, 0], [1, 0, 1], [1, 0, 1], [1, 1, 1], [1, 1, 0], [1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 0]]
newlist = []
for i in range(int(len(list)/2)):
    newlist = (''.join(list for n in range(2)))

print(newlist)
Posted
Updated 8-Nov-22 1:51am

1 solution

Try
Python
l0 = [[1, 1, 1], [1, 1, 0], [1, 0, 1], [1, 0, 1], [1, 1, 1], [1, 1, 0], [1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 0]]
l1 = [ l0[n]+l0[n+1] for n in range(len(l0)) if n%2 == 0 ]
print(l1)
 
Share this answer
 
Comments
Richard MacCutchan 8-Nov-22 11:19am    
+5, nice.
CPallini 8-Nov-22 15:57pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900