Prompt Details
Model
(gemini-3.1-pro)
Token size
258
Example input
[Programming Language]: Python
[User Experience Level]: Beginner
[Specific Goal or Issue]: Remove all even numbers from a list.
[Code Snippet]: numbers = 1, 2, 3, 4, 5, 6 for num in numbers: if num % 2 == 0: numbers.remove(num) print(numbers)
[Desired Output Format]: Please provide the final audit in an Annotated Code Block for maximum clarity.
Example output
# --- AUDIT RESULTS ---
# 1. CRITICAL MISTAKE: Modifying a list while iterating over it causes the loop
# to skip the element immediately following a removal. This is why [1, 3, 5]
# might look right here, but larger datasets will fail silently.
# 2. OPTIMIZATION: List comprehensions are faster and more "Pythonic."
# --- REFACTORED SOLUTION ---
numbers = [1, 2, 3, 4, 5, 6]
# Using a list comprehension creates a new filtered list safely.
numbers = [num for num in numbers if num % 2 != 0]
print(numbers) # Output: [1, 3, 5]
# --- EDUCATIONAL SUMMARY ---
# Concept: "Iterator Invalidation." In Python, never mutate the collection
# you are currently looping through. Instead, create a copy or use a filter.
By downloading this prompt, you agree to our terms of service
GEMINI-3.1-PRO
Stop wasting hours hunting for elusive bugs. This elite Gemini-powered Code Auditor identifies syntax errors, logical flaws, and security vulnerabilities in seconds. Whether you're a student or a senior dev, use this prompt to receive a detailed breakdown of mistakes, optimized refactoring suggestions, and performance tips. Perfect for code reviews, learning new languages, or ensuring production-ready scripts. Clean your code, boost performance, and ship with confidence!
...more
Added 6 days ago
