#NEWLINE# def get_first_delim( text , delims ) : #NEWLINE# #INDENT# '\n    We want to find the first delimiter inside the current text.\n    It could be one of a few delimiters (that are in the delims list), so\n    we search for all of the beginning delimiters, and pick the first one\n    that we find.\n    ' #NEWLINE# locs = [ ] #NEWLINE# for ( ds , de ) in delims . items ( ) : #NEWLINE# #INDENT# loc = text . find ( ds ) #NEWLINE# if ( loc < 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# locs . append ( ( loc , ds ) ) #NEWLINE# #UNINDENT# if ( len ( delims ) == 0 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# return min ( locs , key = ( lambda x : x [ 0 ] ) )