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.

13
  • 2
    What's wrong with your current approach? Seems pretty compact and relatively efficient to me. Commented Mar 11, 2013 at 6:10
  • @DavidRobinson Nothing wrong per se. But in my program s can get fairly large, so I would prefer something a little more efficient, especially if I can get a little more efficiency without coding too hard. Commented Mar 11, 2013 at 6:14
  • 1
    What makes you think your approach isn't efficient? In any approach, you'll have to compare all the values in the tuple at some point, and tuple multiplication is very fast (certainly faster than doing a for loop and checking subtuples). The only optimization I can see is changing range(1, len(s)) to range(1, len(s) / 2). Commented Mar 11, 2013 at 6:16
  • @DavidRobinson I wasn't sure if there was any easy way to beat O(n^2). And is tuple multiplication really better than checking subtuples? I was also afraid that when s gets really large tuple multiplication would build large tuples, even when the comparison fails early on. Commented Mar 11, 2013 at 6:28
  • You should be able to use suffix trees to do it in O(n) (or O(n log n)) time, but I would not call it "slick". What is your definition of slick? I find your naive method slick... Commented Mar 11, 2013 at 6:30