From 3701e5655a41ba481c02cd14903e57aa25a275fe Mon Sep 17 00:00:00 2001 From: wirawan Date: Fri, 28 May 2010 18:46:53 +0000 Subject: [PATCH] * added str_grep and str_igrep. --- text_tools.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/text_tools.py b/text_tools.py index d79f502..250ee85 100644 --- a/text_tools.py +++ b/text_tools.py @@ -1,4 +1,4 @@ -# $Id: text_tools.py,v 1.3 2010-02-24 14:28:13 wirawan Exp $ +# $Id: text_tools.py,v 1.4 2010-05-28 18:46:53 wirawan Exp $ # # wpylib.text_tools # Created: 20091204 @@ -104,6 +104,13 @@ def str_expand(template, params, maxiter=100): return str1 +def str_grep(S, strs): + return [s for s in strs if s.find(S) >= 0] + +def str_igrep(S, strs): + return [i for (s,i) in zip(strs,xrange(len(strs))) if s.find(S) >= 0] + + def slice_str(s): return "%s:%s:%s" % ( ifelse(s.start == None, "", str(s.start)),