def split_code_at_show(text):
 parts = []
 is_doctest = contains_doctest(text)
 part = []
 for line in text.split(u'\n'):
  if (((not is_doctest) and (line.strip() == u'plt.show()')) or (is_doctest and (line.strip() == u'>>> plt.show()'))):
   part.append(line)
   parts.append(u'\n'.join(part))
   part = []
  else:
   part.append(line)
 if u'\n'.join(part).strip():
  parts.append(u'\n'.join(part))
 return parts

def split_code_at_show ( text ) : parts = [ ] is_doctest = contains_doctest ( text ) part = [ ] for line in text . split ( u'\n' ) : if ( ( ( not is_doctest ) and ( line . strip ( ) == u'plt.show()' ) ) or ( is_doctest and ( line . strip ( ) == u'>>> plt.show()' ) ) ) : part . append ( line ) parts . append ( u'\n' . join ( part ) ) part = [ ] else : part . append ( line ) if u'\n' . join ( part ) . strip ( ) : parts . append ( u'\n' . join ( part ) ) return parts
split code at plt .