Basically what i'm trying to do is take every 5 elements from an existing list and then add those elements as a string into another list. For example the below list would output ['12345', '54321']... My attempts so far are below i'm new to coding and would appreciate help best regards Jake
string = ['1', '2', '3', '4', '5', '5', '4', '3', '2', '1']
counter = len(string)
holder = ''
final = []
while counter > 0:
for i in string:
if len(holder) >= 5:
final.append(holder)
holder = ''
counter -= 1
else:
holder += i
counter -= 1
Current output gives me this ['12345'] with holder containing '4321' and counter equaling 0 i guess the fact that the '5' is missing has caused the if statement not to trigger but where has the missing '5' Gone