Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

String subsequencies

gabrimat (5630 points)
2 4 25
in HW3 optional by (5.6k points)
reshown by

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.

232 views
closed

2 Answers

Best answer
gabriel.bustamante (2540 points)
3 6 20
by (2.5k 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)
7 10 22
by (5.8k 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 4 25
by (5.6k points)
Yes I was talking in the perspective of hw3