How to start a cycle in a loop and immediately continue in parallel the main loop?

while True: while True: print('loop2') print('loop1') 

Closed due to the fact that the essence of the question is not clear to the participants 0xdb , freim , Grundy , mkkik , aleksandr barakin 26 Apr at 14:42 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    If you need to go through two entities in parallel, for example, two lists or two generators, then you can use the zip function.

    Sample code from the link above:

     a = ("John", "Charles", "Mike") b = ("Jenny", "Christy", "Monica") x = zip(a, b) for pair in x: print(pair) 

    At the exit:

     ("John", "Jenny"), ("Charles", "Christy") ("Mike", "Monica") 

    If you still want to run a lot of sub-cycles in parallel, then you need streams, as you have already answered ...

       while True: print("loop2") def loop1(): print("loop1") loop1()