python - Is that pythonic? -


if question waste of board, i'll remove it:)

i'm new python wanna evaluation code because i'm c language.

it's function extracting words string between 2 words.

def extract(s,start,end):     return s[s.index('start')+1:s.index('end')] 

it pythonic? or there standard function doing same thing?

thanks:)

i think pythonic you'll get:

def extract(s, start, end):   return s[s.index(start) + len(start):s.index(end)] 

i added + len(start) account length of start variable.

or .partition():

>>> 'get stuff here'.partition('get')[-1].partition('here')[0] ' stuff ' 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -