#NEWLINE# def grep( pat , list , case = 1 ) : #NEWLINE# #INDENT# 'Simple minded grep-like function.\n    grep(pat,list) returns occurrences of pat in list, None on failure.\n\n    It only does simple string matching, with no support for regexps. Use the\n    option case=0 for case-insensitive matching.' #NEWLINE# out = [ ] #NEWLINE# if case : #NEWLINE# #INDENT# for term in list : #NEWLINE# #INDENT# if ( term . find ( pat ) > ( - 1 ) ) : #NEWLINE# #INDENT# out . append ( term ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# lpat = pat . lower ( ) #NEWLINE# for term in list : #NEWLINE# #INDENT# if ( term . lower ( ) . find ( lpat ) > ( - 1 ) ) : #NEWLINE# #INDENT# out . append ( term ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if len ( out ) : #NEWLINE# #INDENT# return out #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None