Skip to content

Instantly share code, notes, and snippets.

View maneeshdisodia's full-sized avatar

maneesh disodia maneeshdisodia

  • AI Architect @ Altimetrik
  • India
View GitHub Profile
@maneeshdisodia
maneeshdisodia / string_wrapper
Created August 13, 2018 12:13
to find n wraps in string
def search(text,n):
'''Searches for text, and retrieves n words either side of the text, which are retuned seperatly'''
word = r"\W*([\w]+)"
groups = re.search(r'{}\W*{}{}'.format(word*n,'place',word*n), text).groups()
return groups[:n],groups[n:]
t = "The world is a small place, we should try to take care of it."
search(t,3)
#(('is', 'a', 'small'), ('we', 'should', 'try'))
@maneeshdisodia
maneeshdisodia / string_wrapper
Created August 13, 2018 12:12
to find n wraps in string
def search(text,n):
'''Searches for text, and retrieves n words either side of the text, which are retuned seperatly'''
word = r"\W*([\w]+)"
groups = re.search(r'{}\W*{}{}'.format(word*n,'place',word*n), text).groups()
return groups[:n],groups[n:]
t = "The world is a small place, we should try to take care of it."
search(t,3)
#(('is', 'a', 'small'), ('we', 'should', 'try'))