Skip to content Skip to sidebar Skip to footer

List Manipulation And Recursion

I have a mansory-grid in a pdf-page. The grid is choosen randomly, so i do not know how much upright cells or cross cells I have to fill. In my list I have all images that I want t

Solution 1:

It's somewhat unclear to me if you are intentionally trying to skip items on each pass or if that's accidental on your part as a side effect of your code. That is, it looks like a bug to me, but maybe it's a feature and not a bug.

If I wanted to remove 5 items from a list as a group and do something with them then recurse the function, I'd do this:

deffill_layout(images):
    out_items = []
    whilelen(out_items) <5and images:
        out_items.append(images.pop(0))
    # do something to your 5 or less items in out_itemsif images:
        fill_layout(images)

Note, you don't need to recurse, you could just handle everything in the function. Further, you could just slice the list into 5 lengths and handle each one as you go. There is a lot of artificial complexity in your method and I don't know how much is actually needed from your example -- so I did this to keep the groups of 5, remove from list and recurse. There are probably simpler ways to do what you want.

Post a Comment for "List Manipulation And Recursion"