Need help with list [name,hit,wall,name,hit,wall,name,hit,wall,name,hit ,wall... ]

I’ve created a list [name,hit,wall,name,hit,wall,name,hit,wall,name,hit,wall… you get the idea ] but I’m stucked when I wanted to use for loops to iterate the list and treat the 3 items [name,hit,wall] as a single object(which they are) and continue for the next 3 items and so forth… I need some advices on how to unpack this mess? lol



for i in range(0, len(items), 3):
    name, hit, wall = items[i: i+3]


It’s better to be more careful when creating the list, but there is a technique you can use if somehow you’ve been given a list like that (When working with images files in the past I found all the color and pixel data in a single list, I had to cycle through groups of 4 RGBA to assemble the data I needed).

list  = [name,hit,wall,name,hit,wall,name,hit,wall,name,hit ,wall... ]

short_list = []
long_list = []

while len(list) > 0:
    if len(short_list) < 3:
        entry = list.pop(0)
        short_list.append(entry)
    else:
        long_list.append(short_list)
        short_list = []

for group in long_list:
    name, hit, wall = group
    do_something()


At the end of that, you should have an empty list and a “long_list” now with all the entries bunched in to groups of 3.
You could modify it, performing the action you need to do once the short_list length is => 3 would make the code a little quicker to run.

EDIT: Just saw agoose’s code,

That would be much quicker and better.

@@agoose77, Thank you so much as always

@@Smoking_mirror, Thanks for the tips as well, its always good to know alternatives(might come in handy later somehow)