AI Skill Report Card
Using Python Builtins
Quick Start12 / 15
When writing Python code, prefer built-in functions over manual implementations:
Python# Instead of manual iteration with index tracking i = 0 for item in items: print(i, item) i += 1 # Use enumerate() for i, item in enumerate(items): print(i, item)
Recommendation▾
Add more diverse concrete examples showing 'bad' vs 'good' output side-by-side rather than just 'good' snippets to better illustrate contrast.
Workflow11 / 15
- Identify the task pattern - iteration, transformation, filtering, type checking, I/O, etc.
- Check for a built-in match before writing custom logic or importing a library.
- Verify signature and edge cases - check argument order, default values, and return types.
- Prefer built-ins over
itertools/manual code when a direct built-in exists; reach foritertoolsonly for more complex iterator composition. - Combine built-ins idiomatically (e.g.,
sorted(data, key=..., reverse=True),zip(*pairs)).
Recommendation▾
The workflow section is generic and could be trimmed or merged with Quick Start since it doesn't add much procedural depth beyond 'check builtins first'.
Common Built-ins by Category
Iteration & Sequences
enumerate(iterable, start=0)— index/value pairszip(*iterables, strict=False)— parallel iteration; usestrict=True(3.10+) to catch length mismatchesmap(func, *iterables),filter(func, iterable)— prefer comprehensions for readability unless chaining lazilyreversed(seq),sorted(iterable, key=None, reverse=False)range(start, stop, step)all(iterable),any(iterable)— short-circuiting boolean checkssum(iterable, start=0),min(),max()(supportkey=anddefault=)
Type & Object Introspection
isinstance(obj, cls_or_tuple)— prefer overtype(obj) == clsissubclass(cls, classinfo)callable(obj),hasattr(obj, name),getattr(obj, name, default),setattr()type(obj)— for introspection; useisinstance()for checks
Functional / Higher-order
sorted(..., key=lambda x: ...)over custom sort loopsfunctoolscomplements builtins forreduce,partial,lru_cache(not builtin, but commonly paired)
I/O
open(file, mode='r', encoding=None, ...)— always passencoding='utf-8'explicitly for text mode to avoid platform-dependent behaviorprint(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)input(prompt=None)
Conversion & Construction
list(),tuple(),dict(),set(),frozenset(),str(),int(),float(),bytes(),bytearray()int(x, base=10)— supports parsing non-base-10 stringschr()/ord()for char-codepoint conversionformat(value, format_spec)— underlies f-strings
Object/Class utilities
super(),property(),staticmethod(),classmethod()vars(obj),dir(obj),id(obj)iter(obj, sentinel=None),next(iterator, default)
Evaluation (use cautiously)
eval(),exec(),compile()— avoid on untrusted input; preferast.literal_eval()for safe literal parsing
Examples14 / 20
Example 1: Input: Need to check if all elements in a list are positive. Output:
Pythonall(x > 0 for x in numbers)
Example 2: Input: Need to iterate two lists together and stop safely on mismatched lengths. Output:
Pythonfor a, b in zip(list1, list2, strict=True): ...
Example 3: Input: Need to safely parse a string that might represent a Python literal (list, dict, number). Output:
Pythonfrom ast import literal_eval value = literal_eval(user_input) # NOT eval(user_input)
Example 4: Input: Need to open a config file for reading text. Output:
Pythonwith open("config.yaml", "r", encoding="utf-8") as f: contents = f.read()
Recommendation▾
Include a decision-table or quick-reference mapping common tasks (e.g., 'need unique items' -> set(), 'need sorted unique' -> sorted(set())) to speed up applied use.
Best Practices
- Always use
with open(...)for file handling — never leave files unclosed. - Explicitly set
encoding="utf-8"when opening text files; don't rely on system default. - Prefer
isinstance(x, (int, float))over chainedtype()checks; tuple form checks multiple types. - Use
sorted(..., key=...)instead ofsorted(..., cmp=...)(cmp removed since Python 3). - Use
next(iterator, default)to avoidStopIterationboilerplate. - Use
zip(..., strict=True)(3.10+) whenever lengths must match, to fail loudly on bugs. - Use
min()/max()withdefault=when the iterable might be empty, to avoidValueError.
Common Pitfalls
- Never use bare
eval()/exec()on user input — arbitrary code execution risk. Useast.literal_evalinstead. - Don't compare types with
==(type(x) == list) — useisinstance()to respect subclassing. - Don't forget
zip()truncates silently to the shortest iterable unlessstrict=Trueis passed. - Don't use mutable default arguments in functions that wrap builtins (e.g.,
def f(x, opts=[])) — classic Python bug, unrelated to builtins directly but often surfaces when combining withmap/filter. - Avoid
open()withoutencodingon cross-platform code — Windows vs. Linux default encodings differ. - Don't use
map()/filter()chained deeply where a generator expression or comprehension would be clearer.