Sequences and Strings

  1. Zero-Based Indexing

    A zero-based index counts how many steps an element is from the start of a sequence.

    Undergraduate
  2. Negative Indices in Python Sequences

    A negative index identifies a position relative to the sequence's end when the sequence supports that convention.

    Undergraduate
  3. Half-Open Slices of Sequences

    A slice with step one usually includes its start offset and excludes its stop offset. Its bounds describe the spaces between successive elements.

    Undergraduate
  4. Steps and Direction in a Slice

    A slice step controls the spacing and direction of selected positions. Negative steps visit the sequence from right to left.

    Undergraduate
  5. Slice Bounds and Single-Index Bounds

    Python's built-in sequences treat excessive slice endpoints and an excessive single index differently.

    Undergraduate
  6. Appending, Inserting, and Extending a List

    Appending adds one item, inserting puts an item at a specified position, and extending draws items from an iterable.

    Undergraduate
  7. Removing a List Element by Value or Position

    The value-based removal of a list element finds a matching value. Position-based removal identifies which occurrence by index.

    Undergraduate
  8. Copying a Sequence with a Slice

    A full slice of a Python list creates another outer list. Nested mutable values can still be shared.

    Undergraduate
  9. Sequence Repetition and Shared Elements

    Repetition can duplicate references in a sequence. It may leave repeated positions sharing a single mutable object.

    Undergraduate
  10. Sequences for Stacks and Queues

    Choose the operations your sequence needs most often, since front and back operations can have different costs.

    Undergraduate
  11. Finding a Value in an Ordered Sequence

    A sequence can be searched in visitation order. A sorted sequence also gives information from each comparison that can eliminate positions.

    Undergraduate
  12. Stable Ordering of Equal-Key Items

    A stable sort keeps the relative order of inputs whose sort keys compare equal.

    Undergraduate
  13. Sorting With a Key Function

    A key function maps each item to the value the sort should use in comparisons. Keep it consistent with what the result is meant to show.

    Undergraduate
  14. Sorting in Place or Producing a Sorted Copy

    Changing a list in place exposes the order to existing references. A sorted result returned as a separate list can preserve source order.

    Undergraduate
  15. Rows and Columns in Nested Lists

    A nested list commonly uses one index to choose a row and another to choose a value inside it.

    Undergraduate
  16. Flattening a Rectangular Grid by Rows

    A rectangular grid stored row by row can translate coordinates into one-dimensional offsets if its width is fixed.

    Undergraduate
  17. Finding a Delimiter or Splitting Text

    Finding a delimiter yields a position or a missing marker. Splitting uses rules that decide how many fields to produce.

    Undergraduate
  18. Stripping Text and Removing an Exact Prefix

    Stripping removes characters from the ends according to a character set. Removing a prefix checks a single complete leading substring.

    Undergraduate
  19. Joining a Sequence of Text Fragments

    A separator-based join places a delimiter between neighboring fragments and gives an exact layout for empty and singleton inputs.

    Undergraduate
  20. Substrings and Subsequences

    A substring occupies contiguous positions. A subsequence preserves relative order while allowing gaps.

    Undergraduate
  21. Removing Duplicates While Preserving Input Order

    An order-preserving deduplication walks the input and emits a value only at the first key occurrence.

    Undergraduate
  22. Counting Consecutive Runs of Symbols

    A run consists of adjacent equal symbols. Tracking its length can summarize a sequence while preserving changes in order.

    Undergraduate
  23. Code Points and Visible Characters in Strings

    A text position may count bytes, Unicode code points, or grapheme clusters, which represent many visible character units.

    Undergraduate
  24. Unicode Normalization and Text Equality

    Normalization produces a prescribed form for canonically equivalent text so independently stored spellings can compare consistently.

    Undergraduate
  25. Whitespace and Empty Fields in Text Records

    Separators, padding, and meaningful space can coexist in one file. A parser needs an explicit rule for which to preserve.

    Undergraduate
  26. Checking Prefixes and Suffixes of Text

    A prefix must start at the first position, and a suffix must reach the last. A general substring can occur anywhere.

    Undergraduate
  27. Choosing a List or Tuple for an Interface

    Sequences can represent a variable list of items or a fixed arrangement of fields. Their mutability and positional meaning are separate design choices.

    Undergraduate
  28. Rotating a Sequence by an Offset

    A rotation changes the front of a sequence while preserving its cyclic order. Normalize the offset before splitting.

    Undergraduate
  29. Longest Common Prefix of Strings

    A longest common prefix stops where any supplied string ends or the next code points disagree.

    Undergraduate
  30. Ordering a Sequence of Events

    A sequence can store arrival order, time order, or another ordering rule. Choose consistently before computing neighbors or the latest event.

    Undergraduate