2 ms·
It is markedly less efficient since you will test y every time for each x, as opposed to once. O(1) vs O(n)
by rich_sasha 4y ago
It is markedly less efficient since you will test y every time for each x, as opposed to once. O(1) vs O(n)
- henrydark 4y agoSpecifically the original double loop example also has this behavior and complexity. If the loops were written as for y in a2: if cond: break for x in a1: # something then they would have O(|a2|) complexity instead of O(|a1||a2|), but then we also don't need break break