Promptbibliothek
Code-Berater
Ressourcen
- Overview
- Schnellstarts
- Claude 3 Modellkarte
- Claude 3.7 Systemkarte
- Systemstatus
- Anthropic Kurse
- Promptbibliothek
- Prompt-Bibliothek
- Kosmische Tastenanschläge
- Unternehmensweissager
- Website-Assistent
- Excel-Formel-Experte
- Google Apps Scripter
- Python-Fehlerbeheber
- Zeitreiseberater
- Geschichten-Begleiter
- Quellen zitieren
- SQL-Zauberer
- Traumdeuter
- Wortspiel-Experte
- Kulinarischer Kreator
- Kofferwort-Poet
- Hal der humorvolle Helfer
- LaTeX-Legende
- Stimmungs-Kolorierung
- Git gud
- Vergleichs-Savant
- Ethischer Dilemma-Navigator
- Protokollführer für Meetings
- Redewendungs-Erklärer
- Code-Berater
- Funktionsgenerator
- Neologismus-Ersteller
- CSV-Konverter
- Emoji-Kodierer
- Textpolierer
- Perspektiven-Abwäger
- Quizfragen-Generator
- Achtsamkeits-Mentor
- Vereinfacher für die zweite Klasse
- VR-Fitness-Innovator
- PII-Bereiniger
- Memo-Meister
- Karrierecoach
- Bewertungsexperte
- Zungenbrecher
- Interviewfragen-Ersteller
- Grammatik-Genie
- Rate mal
- Code-Erklärer
- Außerirdischer Anthropologe
- Datenorganisator
- Markenentwickler
- Effizienzschätzer
- Bewertungsklassifikator
- Anweisungsdekoder
- Motivierende Muse
- E-Mail-Extraktor
- Meister-Moderator
- Unterrichtsplaner
- Sokratischer Weiser
- Alliterations-Alchemist
- Futuristischer Modeberater
- Polyglotte Superkräfte
- Produktnamen-Profi
- Philosophische Betrachtungen
- Tabellenkalkulationszauberer
- Science-Fiction-Szenario-Simulator
- Adaptiver Editor
- Babels Übertragungen
- Tweet-Tonalitätsdetektor
- Flughafen-Code-Analyst
Promptbibliothek
Code-Berater
Schlage Verbesserungen vor, um die Leistung von Python-Code zu optimieren.
Kopiere diesen Prompt in unsere Entwickler-Console, um es selbst auszuprobieren!
Inhalt | |
---|---|
System | Deine Aufgabe ist es, den bereitgestellten Python-Code-Ausschnitt zu analysieren und Verbesserungen vorzuschlagen, um seine Leistung zu optimieren. Identifiziere Bereiche, in denen der Code effizienter, schneller oder ressourcenschonender gestaltet werden kann. Gib spezifische Vorschläge zur Optimierung sowie Erklärungen, wie diese Änderungen die Leistung des Codes verbessern können. Der optimierte Code sollte die gleiche Funktionalität wie der ursprüngliche Code beibehalten, während er eine verbesserte Effizienz aufweist. |
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 |
Beispiel-Output
Python
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
Erklärung: Die Verwendung einer Generator-Funktion mit yield ist speichereffizienter für die Erzeugung der Fibonacci-Folge. Sie vermeidet das Erstellen und Speichern der gesamten Sequenz in einer Liste. Stattdessen erzeugt sie jede Zahl bei Bedarf.
API-Anfrage
import anthropic
client = anthropic.Anthropic( # standardmäßig 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( # standardmäßig 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", // standardmäßig 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
# Siehe https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
# für Authentifizierungsoptionen
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";
// Siehe https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
// für Authentifizierungsoptionen
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';
// Liest aus den Umgebungsvariablen `CLOUD_ML_REGION` & `ANTHROPIC_VERTEX_PROJECT_ID`.
// Durchläuft zusätzlich den Standard-`google-auth-library`-Flow.
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?
On this page