Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • \$\begingroup\$ Surely given x="a" and y="ab" you would exit the loop with y=="b" and return false? \$\endgroup\$ Commented Apr 15, 2012 at 22:29
  • \$\begingroup\$ @PeterTaylor Yeah, I noticed when I was running the examples as tests after posting that I've mixed x and y up. In my functions y needs to be a subsequence of x. I think I'd better change them to avoid any confusion. \$\endgroup\$ Commented Apr 15, 2012 at 22:31
  • \$\begingroup\$ You can get this down to 59 chars: def s(x,y): for c in y: if x:x=x[c==x[0]:] return x=="". It doesn't display correctly in a comment, but I think you can see what I mean. (Also, one added space is enough to increase the indent level.) \$\endgroup\$ Commented Apr 15, 2012 at 23:20
  • \$\begingroup\$ @r.e.s. Thanks, Python's not a language I use much as you can probably tell. Nice golfing. (63 characters according to the Codegolf userscript - it must be counting the newlines). \$\endgroup\$ Commented Apr 15, 2012 at 23:26
  • 1
    \$\begingroup\$ You can use extending slicing to protect against x being '' and save several chars by writing x=x[c==x[0:1]:] \$\endgroup\$ Commented Sep 10, 2012 at 7:57