[Tutor] Aschenputtel problem

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Thu Sep 15 23:33:15 CEST 2005

Alan Gauld schreef:
>>I wonder if there is a shorter form of the following idiom:
> Bearing in mind that shorter is not necessarily better...
> [condition(i) and list1.append(i) or list2.append(i) for i in 
> original]

Alas, won't work. This is one of the cases where the ... and ... or ...
idiom doesn't work; this is why I don't like it and don't use it. The
problem is that list1.append(i) returns None, so list2.append(i) is
always called, even if list1.append(i) was already called:

>>> list1 = []
>>> list2 = []
>>> False and list1.append(2) or list2.append(2)
>>> list1, list2
([], [2])
>>> True and list1.append(4) or list2.append(4)
>>> list1, list2
([4], [2, 4])

If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

More information about the Tutor mailing list