Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

Split a list based on a condition

good = [x for x in mylist if x in goodvals]
bad  = [x for x in mylist if x not in goodvals]
Comment

PREVIOUS NEXT
Code Example
Python :: calculating auc 
Python :: import one file into another python 
Python :: how to make a 2d array in python 
Python :: pandas replace word begins with contains 
Python :: micropython wifi 
Python :: normalizer in sklearn 
Python :: operators in python 
Python :: input lstm 
Python :: python skip input 
Python :: upper python python.org 
Python :: remove watermark using python 
Python :: torch.stack 
Python :: get value of 1 field in model django 
Python :: How to Replace substrings in python 
Python :: reload class module python 
Python :: pandas switch column levels 
Python :: Delete All Rows In Table Django 
Python :: 2nd to last index python 
Python :: literal_eval in python 
Python :: set time complexity python 
Python :: pandas df tail 
Python :: get date only from datetimefiel django 
Python :: python align output 
Python :: conv2d default stride 
Python :: python MAX_INT 
Python :: set remove in python 
Python :: how to code a funtion in python 
Python :: docstring in python 
Python :: generate coordinates python 
Python :: negative slicing in python 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =