String subsequencies

gabrimat (5630 points)
2 3 25
asked Nov 6, 2021 in HW3 optional by gabrimat (5,630 points)
reshown Nov 6, 2021 by gabrimat

Hello everybody, i noticed that the count method of iterables and my manual method of counting subsequences does not work in the way like the homework desires. So i was in doubt of how subsequences are intended. For example we want to count '00' in '000010'. Is the frequency of the segment 2 or 3? When a character is taken it is like "burnt" or the only thing that matters is the position of the segment? Sorry if I was not clear and thanks everyone for the attention.

109 views

2 Answers

Best answer
gabriel.bustamante (2540 points)
3 5 20
answered Nov 6, 2021 by gabriel.bustamante (2,540 points)
In the example you wrote the frequency is 3. Overlapping segments are allowed in this exercise, but the .count() method doesn't take them into account. You'll have to find a different way to count them.

"Position" is a good keyword imo
Simone Russolillo (5790 points)
5 10 22
answered Nov 6, 2021 by Simone Russolillo (5,790 points)
If a= '000010' and we want to count the occurances of the substring '00' with the a.count('00') method the result would be 2. You can visualize why this happens by splitting the string: a= '00 00 10'. As you can see the substring '00' is present two times. No character is 'burnt', the string remains exactly like that. This might be confusing because you are counting ho many '00' are in a string with many zeros but if you change the characters it might be clearer.
gabrimat (5630 points)
2 3 25
commented Nov 6, 2021 by gabrimat (5,630 points)
Yes I was talking in the perspective of hw3