How to start a cycle in a loop and immediately continue in parallel the main loop?
while True: while True: print('loop2') print('loop1')
How to start a cycle in a loop and immediately continue in parallel the main loop?
while True: while True: print('loop2') print('loop1')
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 .
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()
Source: https://ru.stackoverflow.com/questions/975065/
All Articles