[lang-ref] ( list_foreach_multi_col ) ( python )
def test_list_foreach_multi_col():
# use zip
items_a = ['A1', 'A2', 'A3', 'A4', 'A5','A6','A7']
items_b = ['B1', 'B2', 'B3', 'B4', 'B5']
items_c = ['C1', 'C2', 'C3', 'C4', 'C5','C6']
r = ''
for a, b, c in zip(items_a, items_b, items_c):
r += f'{a}{b}{c},'
# Note: zip stops at the shortest input (5 items here).
assert r == 'A1B1C1,A2B2C2,A3B3C3,A4B4C4,A5B5C5,'
# Note: to ensure same size, set strict=True
with pytest.raises(ValueError):
for a, b, c in zip(items_a, items_b, items_c, strict=True):
pass # consume the iterator to trigger the length check