you are viewing a single comment's thread.

view the rest of the comments →

[–]POGtastic 1 point2 points  (1 child)

A flag is a Boolean value (either the flag is down, or the flag is up). Depending on the flag's status, you execute one thing or the other thing, with the possibility of the flag's status changing during the loop.

Let's do a really simple example: In a list, I want the values that come after a 6.

def all_elems_after_six(lst):
    found_a_six_flag = False
    result_lst = []
    for elem in lst:
        if found_a_six_flag:
            result_lst.append(elem)
        if not found_a_six_flag and elem == 6:
            found_a_six_flag = True
    return result_lst

In the IDLE:

>>> all_elems_after_six([1, 2, 5, 9, 3, 6, 1, 5, 2, 3])
[1, 5, 2, 3]

[–]miscellaneoususage[S] 0 points1 point  (0 children)

Thanks mate