Check for regular expression in a list

Cecil Westerhof Cecil at decebal.nl
Fri May 26 07:29:55 EDT 2017


To check if Firefox is running I use:
    if not 'firefox' in [i.name() for i in list(process_iter())]:

It probably could be made more efficient, because it can stop when it
finds the first instance.

But know I switched to Debian and there firefox is called firefox-esr.
So I should use:
    re.search('^firefox', 'firefox-esr')

Is there a way to rewrite
    [i.name() for i in list(process_iter())]

so that it returns True when there is a i.name() that matches and
False otherwise?
And is it possible to stop processing the list when it found a match?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list