search in a list??

Mark McEahern marklists at mceahern.com
Mon Aug 19 20:27:01 CEST 2002


> i have a list:
> x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', 
> '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0']
> 
> i want to indentify de nodes with ":", how i can get this?????
> 
> for example:

Short answer:  List comprehensions.

Demo:

  filtered_list = [el for el in x if el.find(":") >= 0]

// m


-





More information about the Python-list mailing list