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
  • 9,280
  • 9
  • 43
  • 57
oren_isp
  • 729
  • 1
  • 7
  • 22

0 Answers0