Libreria di prompt
Consulente di codice
Risorse
- Overview
- Guide rapide
- Scheda modello Claude 3
- Scheda di sistema Claude 3.7
- Stato del sistema
- Corsi Anthropic
- Libreria di prompt
- Libreria di Prompt
- Battute Cosmiche
- Chiaroveggente aziendale
- Creatore di siti web
- Esperto di formule Excel
- Programmatore di script per Google apps
- Cacciatore di bug Python
- Consulente di viaggi nel tempo
- Compagno di narrazione
- Cita le tue fonti
- Stregone SQL
- Interprete dei sogni
- Pun-dit
- Creatore culinario
- Poeta di portmanteau
- Hal l'assistente umoristico
- Leggenda LaTeX
- Coloratore di stati d'animo
- Git gud
- Esperto di similitudini
- Navigatore di dilemmi etici
- Meeting scribe
- Illuminatore di modi di dire
- Consulente di codice
- Fabbricatore di funzioni
- Creatore di neologismi
- Convertitore CSV
- Codificatore di emoji
- Perfezionatore di prosa
- Valutatore di prospettive
- Generatore di quiz
- Mentore di mindfulness
- Semplificatore per la seconda elementare
- Innovatore di fitness VR
- Purificatore di PII
- Maestro dei memo
- Coach di carriera
- Guru della valutazione
- Scioglilingua
- Creatore di domande per colloqui
- Genio della grammatica
- Indovinello per te
- Chiarificatore di codice
- Antropologo alieno
- Organizzatore di dati
- Creatore di brand
- Stimatore di efficienza
- Classificatore di recensioni
- Decodificatore di direzioni
- Musa motivazionale
- Estrattore di email
- Moderatore esperto
- Pianificatore di lezioni
- Saggio socratico
- Alchimista dell'allitterazione
- Consulente di moda futuristica
- Superpoteri poliglotti
- Esperto di nomi di prodotti
- Riflessioni filosofiche
- Mago dei fogli di calcolo
- Simulatore di scenari di fantascienza
- Editor adattivo
- Trasmissioni di Babele
- Rilevatore del tono dei tweet
- Analista di codici aeroportuali
Libreria di prompt
Consulente di codice
Suggerisci miglioramenti per ottimizzare le prestazioni del codice Python.
Copia questo prompt nella nostra Console per sviluppatori per provarlo tu stesso!
Contenuto | |
---|---|
System | Il tuo compito è analizzare lo snippet di codice Python fornito e suggerire miglioramenti per ottimizzare le sue prestazioni. Identifica le aree in cui il codice può essere reso più efficiente, più veloce o meno dispendioso in termini di risorse. Fornisci suggerimenti specifici per l’ottimizzazione, insieme a spiegazioni di come queste modifiche possono migliorare le prestazioni del codice. Il codice ottimizzato dovrebbe mantenere la stessa funzionalità del codice originale dimostrando al contempo una maggiore efficienza. |
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 |
Output di esempio
Python
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
Spiegazione: Utilizzare una funzione generatore con yield è più efficiente in termini di memoria per generare la sequenza di Fibonacci. Evita di creare e memorizzare l’intera sequenza in una lista. Invece, genera ogni numero al volo quando necessario.
Richiesta API
import anthropic
client = anthropic.Anthropic( # predefinito a 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( # predefinito a 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", // predefinito a 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
# Vedi https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
# per le opzioni di autenticazione
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";
// Vedi https://docs.anthropic.com/claude/reference/claude-on-amazon-bedrock
// per le opzioni di autenticazione
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';
// Legge dalle variabili d'ambiente `CLOUD_ML_REGION` e `ANTHROPIC_VERTEX_PROJECT_ID`.
// Inoltre segue il flusso standard di `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?
On this page