AI code generation turns a written request into Python code. It can produce substantial code quickly and avoid typing mistakes, but a plausible-looking result may still contain bugs or inefficiencies. Treat the result as a draft to understand, run, and test—not as a finished solution. section 2.5 section 2.5.1 section 2.5.2
A practical workflow is:
- Work out what the problem requires before prompting. Knowing the problem and the relevant Python features makes both the prompt and the review more effective. section 5.9.1
- State the needed inputs, outputs, operations, and constraints. If input-loading code already exists, ask only for the remaining work; if a dictionary is required rather than Counter, say so. section 5.9.2 section 7.8.1
- Run the result, inspect its behavior, and either refine the prompt or fix the code directly. A small, understood correction can be more efficient than repeated prompting. section 5.9.2 section 21.6.2
Prompt for a focused task
If a list named temperatures is already loaded, a concise prompt is: “Using the list temperatures, find the high, low, mean, and median temperatures, and show how many unique temperatures are in the list.” The generated solution need not reopen the file. Compare its choices with the task: one illustrated solution sorts a copy and averages the middle two values for an even-length list, while a human-written alternative sorts in place and selects one middle position. section 5.9.3
Check the data, not just the syntax
A generated CSV-processing solution checked `if 'Cook' in row:` and wrote only a header. That test looks for a whole field equal to `Cook`; the desired field contains `Cook County, IL`. Checking `if 'Cook' in row[3]:` fixes the selection. Another generated version checked the wrong column as well. The output file revealed an error that runnable code alone did not. section 21.6.2
Review matters beyond correctness. Sending code to an AI tool raises privacy and intellectual-property concerns; tools may cost money and consume substantial resources. More demanding requirements can also defeat them: versions of Copilot and Colaboratory available in mid-2024 failed to handle a combined input-redirection and text-versus-binary counting task correctly. section 2.5.2 section 13.10.1
















