How can I tell if a string pattern exists within any element of a set in Python? -


how can ask if string pattern, in case c, exists within element of set without removing them each , looking @ them?

this test fails, , not sure why. guess python checking if element in set is c, instead of if element contains c:

n [1]: seto = set()  in [2]: seto.add('c123.45.32')  in [3]: seto.add('c2345.345.32')  in [4]: 'c' in seto out[4]: false 

i know can iterate them set make check:

in [11]: x in seto:     if 'c' in x:         print(x)    ....:          c2345.345.32 c123.45.32 

but not looking in case. ok help!

edit

i sorry, these set operations, not list original post implied.

'c' in seto 

this checks see if of members of seto exact string 's'. not substring, string. check substring, you'll want iterate on set , perform check on each item.

any('c' in item item in seto) 

the exact nature of test can changed. instance, if want stricter c can appear:

any(item.startswith('c') item in seto) 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -