This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |