performance - Python : Removing a List from List of List? -


i have set

char={'j','a'} 

and list of list

content = [[1,'j', 2], [2, 'k', 3], [2, 'a', 3], [3,'a', 9], [5, 'j', 9]] 

i trying remove list items in list content, don't have 'j' & 'a' did

li = list(char) char1= np.array(li) content=np.array(content) new_content=[] alphabet in content:     if alphabet[1] in char1:         new_content.append(alphabet) print(new_content) 

is there efficient way of writing? if char , content has more no of elements, computation takes long time.

>>> content = [[1,'j', 2], [2, 'k', 3], [2, 'a', 3], [3,'a', 9], [5, 'j', 9]] >>> char={'j','a'} 

all lists in content have 'j' , 'a':

>>> [x x in content if all(c in x c in char)] [] 

all lists in content have 'j' or 'a':

>>> [x x in content if any(c in x c in char)] [[1, 'j', 2], [2, 'a', 3], [3, 'a', 9], [5, 'j', 9]] 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -