시네마틱 촬영, 강렬한 빛이 있는 행성 위의 추상적인 [주제/환경] 장
Wikiprompt, 무료 프롬프트 백과사전에서
시네마틱 촬영, 강렬한 빛이 있는 행성 위의 추상적인 [주제/환경] 장 생산 준비 완료된 Python 코드를 생성하도록 AI를 안내하는 구조화된 시스템 프롬프트로, 요구 사항 확인, 설계 결정, PEP8 준수, 사용 예시, 요약 카드를 포함합니다.
프롬프트 내용저장
🌐
STEP 1 - Requirements Confirmation
- **Goal:** Build a Python function that takes a list of integers and returns a new list containing only the even numbers, sorted in ascending order.
- **Inputs:** A list of integers (`List[int]`). The list may be empty, contain negative numbers, duplicates, or unsorted values.
- **Outputs:** A new list of integers (`List[int]`) containing only the even numbers from the input, sorted in ascending order.
- **Edge Cases:**
- Empty input list → return empty list.
- No even numbers in input → return empty list.
- Negative even numbers → included and sorted correctly.
- Duplicate even numbers → preserved in output.
- Input list is `None` → raise `TypeError`.
- Input contains non-integer values → raise `TypeError`.
- **Assumptions:**
- The function does not mutate the original list.
- Sorting is stable but order among equal values is irrelevant since they are identical.
---
STEP 2 - Design Decision Log
| Decision | Chosen Approach | Why | Complexity |
|----------|----------------|-----|------------|
| Data Structure | List comprehension for filtering | Concise and Pythonic | O(n) time, O(k) space (k = evens) |
| Sorting | Built-in `sorted()` | Optimized Timsort, stable | O(k log k) time, O(k) space |
| Error Handling | Explicit `TypeError` checks | Clear failure mode for bad input | O(1) |
| Type Hints | Full typing with `List[int]` | Improves IDE support and readability | - |
| Python Version | 3.10+ (uses `list[int]` syntax) | Modern and concise | - |
| Dependency | Standard library only | No external dependencies | - |
---
STEP 3 - Generated Code
```python
"""Filter and sort even numbers from a list of integers."""
from typing import List
def get_sorted_evens(numbers: List[int]) -> List[int]:
"""Return a sorted list of even numbers from the input list.
Args:
numbers: A list of integers. Must not be None and must contain
only integers.
Returns:
A new list containing only the even integers from `numbers`,
sorted in ascending order. If no even numbers exist, returns
an empty list.
Raises:
TypeError: If `numbers` is None or contains non-integer values.
Example:
>>> get_sorted_evens([3, 2, 5, 4, 1])
[2, 4]
"""
if numbers is None:
raise TypeError("Input list cannot be None")
# Validate all elements are integers
if not all(isinstance(x, int) for x in numbers):
raise TypeError("All elements must be integers")
# Filter even numbers and sort
evens = [x for x in numbers if x % 2 == 0]
return sorted(evens)
```
---
STEP 4 - Usage Example
```python
"""Example usage of get_sorted_evens function."""
from typing import List
def get_sorted_evens(numbers: List[int]) -> List[int]:
"""(Function definition as above - included for standalone runnability)"""
if numbers is None:
raise TypeError("Input list cannot be None")
if not all(isinstance(x, int) for x in numbers):
raise TypeError("All elements must be integers")
evens = [x for x in numbers if x % 2 == 0]
return sorted(evens)
if __name__ == "__main__":
# Normal case with unsorted, mixed numbers
sample_input = [7, 2, 9, 4, 1, 6]
result = get_sorted_evens(sample_input)
print(f"Input: {sample_input}")
print(f"Output: {result}") # Expected: [2, 4, 6]
# Edge case: empty list
empty_result = get_sorted_evens([])
print(f"Empty input -> {empty_result}") # Expected: []
# Edge case: no even numbers
no_evens = get_sorted_evens([1, 3, 5])
print(f"No evens -> {no_evens}") # Expected: []
# Edge case: negative and duplicate evens
negatives = get_sorted_evens([-4, 2, -2, 2, 0])
print(f"Negatives/dupes -> {negatives}") # Expected: [-4, -2, 0, 2, 2]
# Edge case: invalid input (None)
try:
get_sorted_evens(None)
except TypeError as e:
print(f"None input -> TypeError: {e}")
# Edge case: invalid input (non-integer)
try:
get_sorted_evens([1, "two", 3])
except TypeError as e:
print(f"Non-int input -> TypeError: {e}")
```
**Expected Output:**
```
Input: [7, 2, 9, 4, 1, 6]
Output: [2, 4, 6]
Empty input -> []
No evens -> []
Negatives/dupes -> [-4, -2, 0, 2, 2]
None input -> TypeError: Input list cannot be None
Non-int input -> TypeError: All elements must be integers
```
---
STEP 5 - Blueprint Card
| Area | Details |
|---------------------|----------------------------------------------|
| What Was Built | A pure function `get_sorted_evens` that filters even integers from a list and returns them sorted ascending. |
| Key Design Choices | List comprehension for filtering; built-in `sorted()` for sorting; explicit type validation before processing. |
| PEP8 Highlights | snake_case function name; line length ≤79; proper import ordering; Google-style docstring with Args/Returns/Raises/Example. |
| Error Handling | Raises `TypeError` for `None` input or non-integer elements; no silent failures. |
| Overall Complexity | Time: O(n + k log k) where n = input size, k = number of evens | Space: O(k) for output list |
| Reusability Notes | Function is stateless and side-effect-free; can be imported and used anywhere. Could be extended with a `reverse` parameter or custom key function if needed. |
전체 프롬프트를 보려면 로그인하세요
Continue with:
By logging in, you agree to our Terms of Use and Privacy Policy
사용법
이 프롬프트는 coding와 함께 사용하도록 설계되었습니다. 위의 프롬프트 내용을 복사하여 원하는 AI 도구에 붙여넣으세요.
최상의 결과를 얻으려면 자리 표시자(대괄호 또는 대문자로 표시)를 특정 요구 사항으로 사용자 지정할 수 있습니다.
토론
댓글 0개