regex - Text search elements in a big python list -


with list looks like:

cell_lines = ["ln18_central_nervous_system","769p_kidney","786o_kidney"] 

with dabbling in regular expressions, can't figure out compelling way search individual strings in list besides looping through each element , performing search.

how can retrieve indices containing "kidney" in efficient way (since have list of length thousands)?

make list comprehension:

[line line in cell_lines if "kidney" in line] 

this o(n) since check every item in list contain kidney.

if need make similar queries often, should think reorganizing data , have dictionary grouped categories kidney:

{     "kidney": ["769p_kidney","786o_kidney"],     "nervous_system": ["ln18_central_nervous_system"] } 

in case, every "by category" lookup take "constant" time.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -