Answers for "split list in two based on condition python"

0

Split a list based on a condition

good, bad = [], []
for x in mylist:
    (bad, good)[x in goodvals].append(x)
    
# good.append(x) if x in goodvals else bad.append(x)
# for x in mylist: (good if isgood(x) else bad).append(x)
# (good if x in goodvals else bad).append(x)
Posted by: Guest on October-16-2021
0

split list in two based on condition python

good = [x for x in mylist if x in goodvals]
bad  = [x for x in mylist if x not in goodvals]
Posted by: Guest on October-16-2021

Code answers related to "split list in two based on condition python"

Python Answers by Framework

Browse Popular Code Answers by Language