Monday, 15 June 2015

Removing a string that does not contain letters from a list of strings in python -



Removing a string that does not contain letters from a list of strings in python -

i making text analyzer in python. trying remove string not contain letters or integers list. stuck , not know how so. when counting length of list including string '-' , not want because don't want count word. i'd rather not utilize string.remove('-') because want work other inputs.

thanks in advance.

i think mean want filter out strings no alphanumeric characters list of strings. ['a','b','*'] => ['a','b']

not hard:

in [39]: l = ['adsfg','sdfgb','gdc','56hjfg1','&#$%^',"asfgd3$#$%^" ] in [40]: l = filter (lambda s:any([c.isalnum() c in s]), l) out[41]: ['adsfg', 'sdfgb', 'gdc', '56hjfg1', 'asfgd3$#$%^'] in [42]:

python string python-3.4

No comments:

Post a Comment