如何在python中重启"for"循环?

Mer*_*ero 0 python for-loop python-2.7

我怎么能在python中这样做:

x = [1,2,3,4,5,6]
for i in x:
    if i == 4:
       -restart the loop from beginning-
    else:
        print i
Run Code Online (Sandbox Code Playgroud)

所以这里它将打印到4然后重复循环

sph*_*ere 9

那这个呢:

x = [1,2,3,4,5,6]
restart = True
while restart:
    for i in x:
        # add any exit condition!
        # if foo == bar:
        #   restart = False
        #   break
        if i == 4:
           break
        else:
            print i
Run Code Online (Sandbox Code Playgroud)