Skip to content

Instantly share code, notes, and snippets.

View leenhaj715-code's full-sized avatar

leenhaj715-code

  • Joined Oct 17, 2025
View GitHub Profile
@leenhaj715-code
leenhaj715-code / api_integration.py
Created October 17, 2025 05:19
Fetches data from the Cat Facts public API, handles errors, and returns a clean JSON output with selected fields.
import requests
def get_cat_fact():
url = "https://catfact.ninja/fact"
try:
response = requests.get(url, timeout=5)
response.raise_for_status()
data = response.json()
def find_pairs(arr, target):
pairs = []
seen = set()
added = set()
for num in arr:
diff = target - num
if diff in seen and (min(num, diff), max(num, diff)) not in added:
pairs.append([diff, num])
added.add((min(num, diff), max(num, diff)))