Loading...
    • 開発者ガイド
    • APIリファレンス
    • MCP
    • リソース
    • リリースノート
    Search...
    ⌘K
    リソース
    概要用語集システムプロンプト
    プロンプトライブラリCosmic KeystrokesCorporate clairvoyantWebsite wizardExcel formula expertGoogle apps scripterPython bug busterTime travel consultantStorytelling sidekick出典を引用SQL sorcererDream interpreterPun-ditCulinary creatorPortmanteau poetHal the humorous helperLaTeX legendMood colorizerGit gudSimile savantEthical dilemma navigatorMeeting scribeIdiom illuminatorCode consultantFunction fabricatorNeologism creatorCSV converterEmoji encoderProse polisherPerspectives pondererTrivia generatorMindfulness mentorSecond-grade simplifierVR fitness innovatorPII purifierMemo maestroCareer coachGrading guruTongue twisterInterview question crafterGrammar genieRiddle me thisCode clarifierAlien anthropologistData organizerBrand builderEfficiency estimatorReview classifierDirection decoderMotivational museEmail extractorMaster moderatorLesson plannerSocratic sageAlliteration alchemistFuturistic fashion advisorPolyglot superpowersProduct naming proPhilosophical musingsSpreadsheet sorcererSci-fi scenario simulatorAdaptive editorBabel's broadcastsTweet tone detectorAirport code analyst
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    プロンプトライブラリ

    コードコンサルタント

    Pythonコードのパフォーマンスを最適化するための改善提案を行います。

    このプロンプトを開発者Consoleにコピーして、ご自身で試してみてください!

    Content
    Systemあなたのタスクは、提供されたPythonコードスニペットを分析し、そのパフォーマンスを最適化するための改善提案を行うことです。コードをより効率的、高速、またはリソース消費量の少ないものにできる領域を特定してください。最適化のための具体的な提案を、これらの変更がコードのパフォーマンスをどのように向上させるかの説明とともに提供してください。最適化されたコードは、改善された効率性を実証しながら、元のコードと同じ機能を維持する必要があります。
    Userdef 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リクエスト

    • APIリクエスト