0

I frequently want to split a list based on a condition. I have considered the following two methods.

big = [x for x in mylist if x > cutoff]
small  = [x for x in mylist if x < cutoff]

and

big = []
small = []

for x in mylist:
    if x > cutoff: big.append(x)
    else: small.append(x)

Which method is better from an efficiency and readability point of view. Is there another method I haven't considered which would be better?

Eoin
  • 1
  • 1

0 Answers0