Python Forum
[Discussion] Re. Substring counting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Discussion] Re. Substring counting
#9
Did you read the top post?
In this version we are looking for subsequences, not substrings.
Quote:Extend this to instead give an algorithm that finds the number of times one string occurs as a subsequence in another string.

Whereas a substring must be contiguous, a subsequence need not be, though it must still be in the correct order.

For example if we count occurrences of the subsequence "an" in "banana" we get 3.
Comprised of the following: "banana", "banana", "banana"
I gave a couple sample input/outputs in the OP as well and Grib put them in unittests for convenience.

This is the template with tests:
Reply


Messages In This Thread
Re. Substring counting - by Mekire - Jan-22-2018, 02:56 AM
RE: [Discussion] Re. Substring counting - by Mekire - Jan-22-2018, 08:52 AM
RE: [Discussion] Re. Substring counting - by Mekire - Jan-22-2018, 10:29 AM
RE: [Discussion] Re. Substring counting - by wavic - Jan-22-2018, 11:38 AM
RE: [Discussion] Re. Substring counting - by wavic - Jan-22-2018, 11:43 AM
RE: [Discussion] Re. Substring counting - by Mekire - Jan-22-2018, 12:41 PM
RE: [Discussion] Re. Substring counting - by wavic - Jan-22-2018, 01:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding how many times substring is in a string using re module ranbarr 4 2,958 May-21-2021, 06:14 PM
Last Post: nilamo
  Substring in a string Propoganda 1 2,225 Dec-01-2019, 08:45 AM
Last Post: perfringo
  Find a substring in a dictonary; value substring of key aapurdel 2 7,053 May-31-2019, 06:14 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020