Re: List Partition Comprehension (Feature Suggestion)

2020-09-22 Thread Yakov Shalunov
or _ in range(n)) for x in iter: lists[key(x)].append(x) return lists ``` Except it would be optimized like a library function (which means written in C, I believe) On Tuesday, September 22, 2020 at 12:16:39 PM UTC-7, Yakov Shalunov wrote: > Python list comprehension is substantial

List Partition Comprehension (Feature Suggestion)

2020-09-22 Thread Yakov Shalunov
Python list comprehension is substantially faster than plan iteration, to the point where ``` l0, l1 = [],[] for x in l: if cond(x): l0.append(x) else: l1.append(x) ``` runs at about the same speed as ``` l0 = [x for x in l if cond(x)] l1 = [x for x in l if not cond(x)] ```