Christopher Arndt wrote: > Hi, > > I wonder if there is a shorter form of the following idiom: > > list1 = [] > list2 = [] > for item in original_list: > if condition(item): > list1.append(item) > else: > list2.append(item)
I don't think so. You can write it as two list comprehensions which is shorter but it iterates the original list twice: list1 = [item for item in original_list if condition(item)] list2 = [item for item in original_list if not condition(item)] Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor