プロンプトライブラリ
コードコンサルタント
リソース
- Overview
- クイックスタート
- Claude 3モデルカード
- Claude 3.7 システムカード
- システムステータス
- Anthropic コース
- プロンプトライブラリ
- プロンプトライブラリ
- コズミック・キーストローク
- 企業の千里眼
- ウェブサイトウィザード
- Excelの数式エキスパート
- Google Apps スクリプター
- Pythonバグバスター
- タイムトラベルコンサルタント
- ストーリーテリングの相棒
- 情報源を引用する
- SQLソーサラー
- 夢の解釈者
- ダジャレ名人
- 料理クリエイター
- ポートマントー詩人
- 皮肉屋のヘルパー、ハル
- LaTeX レジェンド
- ムードカラライザー
- Git gud
- 直喩の達人
- 倫理的ジレンマナビゲーター
- 会議の書記
- 慣用句解説者
- コードコンサルタント
- 関数ファブリケーター
- 新語創造者
- CSVコンバーター
- 絵文字エンコーダー
- 文章磨き上げ
- 視点の考察者
- クイズジェネレーター
- マインドフルネスメンター
- 小学2年生向け簡易化ツール
- VRフィットネスイノベーター
- PII 除去ツール
- メモマエストロ
- キャリアコーチ
- 採点の達人
- 早口言葉
- 面接質問作成ツール
- 文法の魔人
- なぞなぞ出題
- コード解説者
- エイリアン人類学者
- データオーガナイザー
- ブランドビルダー
- 効率性評価ツール
- レビュー分類器
- 方向性デコーダー
- モチベーションの源
- メールアドレス抽出ツール
- マスターモデレーター
- 授業計画作成者
- ソクラテス式の賢者
- 頭韻の錬金術師
- 未来的ファッションアドバイザー
- 多言語スーパーパワー
- 製品ネーミングプロ
- 哲学的考察
- スプレッドシートの魔術師
- SFシナリオシミュレーター
- 適応型エディター
- バベルの放送
- ツイートトーン検出器
- 空港コードアナリスト
プロンプトライブラリ
コードコンサルタント
Pythonコードのパフォーマンスを最適化するための改善案を提案します。
このプロンプトを開発者向けコンソールにコピーして、自分で試してみましょう!
内容 | |
---|---|
System | あなたの任務は、提供されたPythonコードスニペットを分析し、そのパフォーマンスを最適化するための改善案を提案することです。コードをより効率的に、より速く、またはリソース消費を抑えることができる領域を特定してください。最適化のための具体的な提案を、これらの変更がコードのパフォーマンスをどのように向上させるかの説明とともに提供してください。最適化されたコードは、元のコードと同じ機能を維持しながら、改善された効率性を示す必要があります。 |
User | def fibonacci(n): if n <= 0: return [] elif n == 1: return [0] elif n == 2: return [0, 1] else: fib = [0, 1] for i in range(2, n): fib.append(fib[i-1] + fib[i-2]) return fib |
出力例
Python
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
説明: yieldを使用したジェネレータ関数は、フィボナッチ数列の生成においてメモリ効率が高くなります。シーケンス全体をリストに作成して保存することを避け、代わりに必要に応じて各数値をその場で生成します。
APIリクエスト
import anthropic
client = anthropic.Anthropic( # デフォルトはos.environ.get("ANTHROPIC_API_KEY")
api_key="my_api_key",
)
message = client.messages.create(
model="claude-opus-4-20250514",
max_tokens=1000,
temperature=0,
system="Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib",
}
],
}
],
)
print(message.content)
import anthropic
client = anthropic.Anthropic( # デフォルトはos.environ.get("ANTHROPIC_API_KEY")
api_key="my_api_key",
)
message = client.messages.create(
model="claude-opus-4-20250514",
max_tokens=1000,
temperature=0,
system="Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib",
}
],
}
],
)
print(message.content)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: "my_api_key", // デフォルトはprocess.env["ANTHROPIC_API_KEY"]
});
const msg = await anthropic.messages.create({
model: "claude-opus-4-20250514",
max_tokens: 1000,
temperature: 0,
system: "Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib"
}
]
}
]
});
console.log(msg);
from anthropic import AnthropicBedrock
# 認証オプションについては https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
# を参照してください
client = AnthropicBedrock()
message = client.messages.create(
model="anthropic.claude-opus-4-20250514-v1:0",
max_tokens=1000,
temperature=0,
system="Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib"
}
]
}
]
)
print(message.content)
import AnthropicBedrock from "@anthropic-ai/bedrock-sdk";
// 認証オプションについては https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
// を参照してください
const client = new AnthropicBedrock();
const msg = await client.messages.create({
model: "anthropic.claude-opus-4-20250514-v1:0",
max_tokens: 1000,
temperature: 0,
system: "Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib"
}
]
}
]
});
console.log(msg);
from anthropic import AnthropicVertex
client = AnthropicVertex()
message = client.messages.create(
model="claude-3-7-sonnet-v1@20250219",
max_tokens=1000,
temperature=0,
system="Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib"
}
]
}
]
)
print(message.content)
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
// `CLOUD_ML_REGION`と`ANTHROPIC_VERTEX_PROJECT_ID`環境変数から読み込みます。
// さらに標準の`google-auth-library`フローを通過します。
const client = new AnthropicVertex();
const msg = await client.messages.create({
model: "claude-3-7-sonnet-v1@20250219",
max_tokens: 1000,
temperature: 0,
system: "Your task is to analyze the provided Python code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code's performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.",
messages: [
{
"role": "user",
"content": [
{
"type": "text",
"text": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib"
}
]
}
]
});
console.log(msg);
Was this page helpful?