I have a list like this. last_1=[['3', '3', '2', 'F', '2', 'C', '2', 'D', '2', 'A', '2', '8', '7', 'C', '3', 'B', '2', 'E', '2', 'E', '3', '3', '3', '4', '3', '3', '3', '0', '3', 'B', '2', '8', '3', '3', '2', 'D', '2', 'E'], ['2', 'C', '2', 'A', '3', '3', '2', 'E', '2', '8', '7', '4', '7', 'A', '5', '3', '7', 'C', '3', '9', '2', 'D', '2', 'F', '2', 'F', '3', 'B', '2', 'E', '3', '8', '7', 'C', '2', '3', '2', 'D', '2', '7', '7', 'C', '2', '8', '2', 'D', '7', 'C', '2', '8', '3', '7', '2', 'A', '2', 'F', '3', '3', '2', 'E', '3', 'B', '2', '8', '3', '7', '7', 'C', '2', '3', '2', 'D', '2', '7', '2', 'A', '7', 'C', '3', '4', '2', '7', '2', 'F', '3', 'B', '2', 'E', '7', 'A', '7', '3'], ['3', '8', '3', '7', '3', '6', '7', 'C', '3', '1', '3', '3', '3', '0', '3', '0', '7', '4', '3', 'B', '2', 'A', '3', '5', '7', '3', '6', '2'], ['7', 'C', '7', 'C', '7', 'C', '7', 'C', '2', 'A', '3', '7', '2', '8', '2', '7', '2', 'A', '2', 'E', '7', 'C', '3', 'B', '2', 'A', '3', '5', '7', 'C', '7', '1', '7', 'C', '7', 'A', '7', 'C', '5', '1', '3', '3', '3', '0', '3', '0', '7', 'C', '3', '7', '2', '4', '3', '7', '3', '9', '2', '7', '2', '8', '3', '7', '3', '8', '7', 'A'], ['3', '1', '3', '3', '3', '0', '3', '0', '7', '4', '7', 'A', '3', '4', '3', '7', '3', '0', '3', '0', '2', 'D', '7', 'A', '7', '3']]
And if you consider that last_1
is a list which have 5 elements. I just want to make group of them with protect of 5 elements. I mean I want to get an output like this:
> output_hexa=[['33','2F','2C',...,'2E'],['2C','2A','33','2E',...,'73'],[....],[...],[...]]
I keep short output because of its length. By the way, this output_hexa
list can change. So, its length might be more than 5 or less than 5. And I have tried something above. What's my wrong? Can you say me?
output_hexa=[]
hexa_output=[]
b=0
indis_one=0
indis_two=1
for i in range(len(last_1)):
for x in last_1:
for j in range((len(x))//2):
if len(output_hexa)-1*(2)==j:
indis_one=0
indis_two=1
hexa_output.extend(output_hexa)
output_hexa=[]
break
else:
pass
output_hexa.insert(j,last_1[i][indis_one]+last_1[i][indis_two])
indis_one+=2
indis_two+=2
print(output_hexa)
It gives IndexError: list index out of range
error.