0

I have a list that I want to split by condition:

l = [1,2,3,7,8,9,4]

to

l1 = [1,2,3,4] , l2 = [7,8,9]

Based on the condition: x > 5. The code is:

l1 = []
l2 = []
for x in l:
    if x > 5:
       l1.append(x)
    else:
       l2.append(x)

Is there a more pythonic/faster way to do it?

petezurich
  • 7,683
  • 8
  • 34
  • 51
oren_isp
  • 649
  • 1
  • 6
  • 19

0 Answers0