Sales AgentsADVANCED
GPT-3.5
4.9

Optimize a Python Function for Speed

Improve the performance of a given Python code snippet

The Prompt

Write a Python function that takes a large array of integers as input. This function should iterate over the array, find pairs of numbers that add up to a target value, and store them in a dictionary where the keys are the pairs and the values are their frequencies. The target value is the sum of all the elements in the array divided by 2. The function should return the dictionary. Use a single loop to iterate over the array, and employ techniques such as memoization or caching to improve performance. The input array will contain at least 100,000 elements and will be randomly generated.

Example Output

[{'(1, 100001)': 1, '(2, 100002)': 1, ...}]

Best Use Cases

Software Development & Coding

Frequently Asked Questions

What is the "Optimize a Python Function for Speed" prompt used for?

Improve the performance of a given Python code snippet

Which AI model works best with this prompt?

This prompt is optimized for GPT-3.5 but also works with Claude 3, Gemini Pro, and other LLMs.

Is this prompt free to use?

Yes — all PromptForgeHub prompts are free to copy and use. Click the copy button and paste into your AI tool.

How difficult is this prompt?

Difficulty: ADVANCED. Best suited for advanced prompt engineers.

Official Source

PromptForgeHub
Verified Official

Details

Views8
CategorySales Agents
AI ModelGPT-3.5
UpdatedJun 25, 2026

Need Custom Prompts?

Our team of prompt engineers can build custom AI workflows for your business needs.

Contact Sales

Explore 1,000+ more AI prompts for business, marketing, eCommerce & more.

Browse All Prompts