Skip to content
CCC Python Course

String processing I: counting, runs and building

Stage
3
Module
M3.3
Lessons
1

In this module

  • Iterate through a string character by character to count runs of identical characters.
  • Build a new string by appending characters inside a loop.
  • Detect when a character changes and reset a counter.

Before this module

Lessons

  1. 1String processing I (counting runs and building)

Practice

Try these on the judges. Each link opens the problem on WMOJ or DMOJ.

  1. 2022 J3
    Harp Tuning (opens on WMOJ in a new tab) WMOJ

    Compress a string by counting consecutive identical characters.

  2. 2020 S1
    Surmising a Sprinter's Speed (opens on DMOJ in a new tab) DMOJ

    Scan a list of values and sort them to work out a consistent pattern.

    Why DMOJ: A scan-and-sort problem that reuses the character-by-character pass from this lesson.

  3. 2024 J3
    Bronze Count (opens on WMOJ in a new tab) WMOJ

    Find a specific ranked value among a set of scores, by counting or sorting.