> 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] This returns a list of booleans that we throw away but the list1,list2 containers will have been modified as required. But the original code(below) is probably more reliable and clearer! > list1 = [] > list2 = [] > for item in original_list: > if condition(item): > list1.append(item) > else: > list2.append(item) > I call this the "Aschenputtel" problem, because it is described > by the famous quote from the fairy tale as told by the > Grimm brothers: > > "Die guten ins Töpfchen, die schlechten ins Kröpfchen." > (The good ones in the pot, the bad ones in the crop) HTH, Alan G.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor