Tracking current during iteration I have a list of posts. I need to generate it each one by one. For generation of each post, I need to know about other posts. However, I want to make the current post marked.

def generate(posts):
    print(posts) #faking generation

def marked_active_post(orig_posts, active_index):
    posts_view = orig_posts.copy()
    active_post = orig_posts[active_index]
    active_post = orig_posts[active_index].copy()
    active_post['active?'] = True
    posts_view[active_index] = active_post
    return posts_view

posts = [{'foo':'bar'}, {'aaa':'bbb'}]
for i in range(0, len(posts)):
    generate(marked_active_post(posts, i))


How can I do better?
It's too bad your template engine doesn't support conditions. What about this?

def marked_active_post(orig_posts, active_index):
    posts_view = orig_posts.deepcopy()
    posts_view[active_index]['active?'] = True
    return posts_view


That means n+1 copies instead of 2, but no need to optimize it until it proves to be slow.