AI Skill Report Card

Working with Python Data Types

B+78·Aug 15, 2026·Source: Web
13 / 15
Python
from datetime import datetime, date, timedelta from collections import defaultdict, Counter, namedtuple from enum import Enum, auto # Common patterns now = datetime.now() tomorrow = date.today() + timedelta(days=1) counts = Counter(["a", "b", "a"]) # Counter({'a': 2, 'b': 1}) Point = namedtuple("Point", ["x", "y"]) p = Point(1, 2) class Color(Enum): RED = auto() GREEN = auto()
Recommendation
Add more diverse examples covering deque, defaultdict, and array usage with concrete input/output pairs rather than concentrating on datetime/enum/namedtuple.
13 / 15
  1. Identify the need: dates/times, structured records, counting/grouping, fixed sets of constants, or memory-efficient sequences.
  2. Pick the right module/type (see decision table below).
  3. Check mutability requirements — use namedtuple/dataclass for immutable records, plain classes or dicts for mutable state.
  4. Consider performancearray for homogeneous numeric data, deque for queue-like operations, set/frozenset for membership tests.
  5. Verify timezone handling for datetime — always prefer timezone-aware objects (datetime.now(timezone.utc)) over naive ones in production code.

Progress checklist for a data-modeling task:

  • Determine if data is temporal, categorical, or collection-based
  • Choose the specific type/module
  • Handle edge cases (timezones, empty collections, enum uniqueness)
  • Add type hints referencing the chosen types
Recommendation
Include a 'bad outcome' example (e.g., mutating a namedtuple or naive datetime bug) to show contrast, not just best practices as prose.
NeedUse
Calendar dates onlydatetime.date
Date + timedatetime.datetime
Time deltas/arithmeticdatetime.timedelta
Timezone-aware timedatetime.timezone, zoneinfo.ZoneInfo
Month/year calendar utilitiescalendar module
Fixed set of named constantsenum.Enum / enum.IntEnum / enum.Flag
Bitwise combinable flagsenum.Flag or enum.IntFlag
Fast countingcollections.Counter
Default values on missing keyscollections.defaultdict
Ordered key-value with move-to-endcollections.OrderedDict
Lightweight immutable recordcollections.namedtuple or typing.NamedTuple
Double-ended queuecollections.deque
Compact numeric arraysarray.array
Fast membership/uniquenessset / frozenset
Weak references to avoid leaksweakref
Sortable priority structuresheapq with lists
Copy semantics (shallow/deep)copy.copy / copy.deepcopy
14 / 20

Example 1: Input: Need to count word frequency in a list of strings. Output:

Python
from collections import Counter freq = Counter(words) freq.most_common(3) # top 3 words

Example 2: Input: Need an immutable, lightweight coordinate object with named fields. Output:

Python
from typing import NamedTuple class Point(NamedTuple): x: float y: float p = Point(1.0, 2.0)

Example 3: Input: Need a set of mutually exclusive status constants with string values for logging. Output:

Python
from enum import Enum class Status(Enum): PENDING = "pending" ACTIVE = "active" DONE = "done" print(Status.ACTIVE.value) # "active"

Example 4: Input: Need to compute the date 90 days from now, timezone-aware. Output:

Python
from datetime import datetime, timedelta, timezone future = datetime.now(timezone.utc) + timedelta(days=90)
Recommendation
The decision table is excellent but could be tied more directly to the workflow steps with cross-references for faster navigation.
  • Always use timezone-aware datetime objects (timezone.utc or zoneinfo.ZoneInfo) rather than naive datetimes to avoid ambiguity across systems.
  • Prefer enum.Enum over plain string/int constants for closed sets of values — it gives type safety and IDE support.
  • Use collections.namedtuple/NamedTuple or dataclasses.dataclass(frozen=True) instead of raw tuples/dicts for structured, self-documenting data.
  • Use defaultdict instead of manually checking if key not in dict.
  • Prefer deque over list for queue/stack operations requiring O(1) appends/pops from both ends.
  • Use array.array only when memory efficiency for large homogeneous numeric data matters; otherwise a list is simpler.
  • Don't use naive datetime objects when comparing across timezones — this silently produces wrong results.
  • Don't mutate a namedtuple — it's immutable by design; use ._replace() to create a modified copy.
  • Don't use list for frequent front-insertion/removal — it's O(n); use deque.
  • Don't compare Enum members by value equality when identity (is) comparisons are expected — use is for enum members.
  • Don't forget that IntEnum/IntFlag members compare equal to plain ints, which can hide bugs if strict typing is desired — prefer plain Enum unless int compatibility is required.
  • Don't deep-copy objects containing unpicklable resources (file handles, sockets) — implement __deepcopy__ explicitly if needed.
0
Grade B+AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
13/15
Workflow
13/15
Examples
14/20
Completeness
17/20
Format
15/15
Conciseness
13/15