So you have two lists:
>>> a = [1,2,3,4,5] >>> b = [6,7,8,9,0]
... and you want to iterate over a and b . So what is a and b , exactly?
>>> a and b [6, 7, 8, 9, 0]
This may seem strange, but it is the result of two facts about Python:
Each object has either True -ish or False -ish. For instance:
>>> bool(a) True >>> bool(b) True
In fact, all lists except the empty list [] are True -ish.
Python uses a short circuit estimate , which means for a and b this is:
Checks if there is a True -ish or False -ish
If a is False -ish, then it is equal to a
If a is True -ish, then b
Following these rules, you should be able to see why a and b evaluates [6, 7, 8, 9, 0] in your case (and by the same rules for combinations of actual values, True and False will show you that evaluating the scheme makes sense).
If what you really want to do is iterate over the elements in a and then in b , you can simply use the + operator to concatenate them:
>>> for item in a + b: ... print item, ... 1 2 3 4 5 6 7 8 9 0
Regarding your follow up questions:
What could happen to other operators like or and not ?
or rules for evaluating a short circuit are different (you can view them yourself or just follow the link above), and in your case a or b is evaluated as [1, 2, 3, 4, 5] (in other words, a ).
not always returns True for the value False -ish and False for the value True -ish, and since you cannot TypeError over True or False TypeError .
Is this the right use, even? If so, is it dirty, insecure, or frowned?
Well, there is nothing illegal about it, but as you can see, it does not do what you want. There are circumstances in which (ab) using a short circuit estimate to select an iteration over which iteration can be performed, but this is not one of them.