Upload knowledge_library.json with huggingface_hub
Browse files- knowledge_library.json +273 -0
knowledge_library.json
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"topic": "python_functions",
|
| 4 |
+
"tags": [
|
| 5 |
+
"python",
|
| 6 |
+
"functions",
|
| 7 |
+
"def",
|
| 8 |
+
"arguments",
|
| 9 |
+
"parameters",
|
| 10 |
+
"return"
|
| 11 |
+
],
|
| 12 |
+
"content": "Python Functions:\n- Define with `def name(params):`, body indented 4 spaces\n- Parameters: positional args, keyword args (name=value), *args (variadic), **kwargs (keyword variadic)\n- Default values: `def f(x=10)`. NEVER use mutable defaults like `def f(x=[])`.\n- Return values: `return value`. No return = returns None.\n- Type hints: `def add(a: int, b: int) -> int:`. Optional.\n- Docstrings: triple-quoted string right after def line.\n- Lambda: `lambda x: x*2` for inline anonymous functions."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"topic": "python_classes",
|
| 16 |
+
"tags": [
|
| 17 |
+
"python",
|
| 18 |
+
"classes",
|
| 19 |
+
"oop",
|
| 20 |
+
"self",
|
| 21 |
+
"inheritance",
|
| 22 |
+
"methods"
|
| 23 |
+
],
|
| 24 |
+
"content": "Python Classes:\n- Define with `class Name:`. Methods take `self` as first param.\n- `__init__(self, ...)` is constructor.\n- Instance variables: `self.var = value` inside __init__.\n- Inheritance: `class Child(Parent):`. Call `super().__init__()` in child __init__.\n- `@property` decorator for computed attributes.\n- `@staticmethod` for methods that don't need self.\n- `@classmethod` with `cls` as first param for factory methods.\n- `__str__` for string representation, `__repr__` for debugging representation."
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"topic": "python_imports",
|
| 28 |
+
"tags": [
|
| 29 |
+
"python",
|
| 30 |
+
"import",
|
| 31 |
+
"modules",
|
| 32 |
+
"packages",
|
| 33 |
+
"from"
|
| 34 |
+
],
|
| 35 |
+
"content": "Python Imports:\n- `import module` imports the whole module. Access with `module.name`.\n- `from module import name` imports specific name into current namespace.\n- `from module import *` imports all public names (avoid this).\n- `import module as alias` for shorter names.\n- `from module import name as alias` for renaming.\n- Packages: directory with `__init__.py` file. Example: `from package.module import name`.\n- Common imports: `import os`, `import sys`, `import json`, `import re`, `import math`."
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"topic": "python_exceptions",
|
| 39 |
+
"tags": [
|
| 40 |
+
"python",
|
| 41 |
+
"exceptions",
|
| 42 |
+
"error",
|
| 43 |
+
"try",
|
| 44 |
+
"except",
|
| 45 |
+
"finally",
|
| 46 |
+
"raise"
|
| 47 |
+
],
|
| 48 |
+
"content": "Python Error Handling:\n- `try:` block contains code that might raise an exception.\n- `except ExceptionType as e:` catches specific exception types.\n- `except Exception as e:` catches (almost) all exceptions.\n- `else:` runs if no exception occurred.\n- `finally:` ALWAYS runs (cleanup code).\n- `raise ValueError(\"message\")` to raise an exception.\n- Common exceptions: ValueError, TypeError, KeyError, IndexError, FileNotFoundError, ZeroDivisionError.\n- Context managers: `with open(path) as f:` auto-closes file even on error."
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"topic": "python_strings",
|
| 52 |
+
"tags": [
|
| 53 |
+
"python",
|
| 54 |
+
"strings",
|
| 55 |
+
"format",
|
| 56 |
+
"f-strings",
|
| 57 |
+
"methods",
|
| 58 |
+
"split",
|
| 59 |
+
"join"
|
| 60 |
+
],
|
| 61 |
+
"content": "Python String Operations:\n- f-strings: `f\"Hello {name}\"` for string formatting.\n- `.format()`: `\"Hello {}\".format(name)`.\n- `.split(sep)`: split into list by separator.\n- `.join(iterable)`: join list into string with separator.\n- `.strip()`, `.lstrip()`, `.rstrip()`: remove whitespace.\n- `.lower()`, `.upper()`, `.title()`, `.capitalize()`: case changes.\n- `.replace(old, new)`: replace substrings.\n- `.startswith(prefix)`, `.endswith(suffix)`: check prefixes/suffixes.\n- `.find(sub)`, `.index(sub)`: find substring position.\n- Slice: `s[start:end:step]`. Reverse: `s[::-1]`."
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"topic": "python_lists",
|
| 65 |
+
"tags": [
|
| 66 |
+
"python",
|
| 67 |
+
"lists",
|
| 68 |
+
"list",
|
| 69 |
+
"array",
|
| 70 |
+
"comprehension",
|
| 71 |
+
"append",
|
| 72 |
+
"slice"
|
| 73 |
+
],
|
| 74 |
+
"content": "Python Lists:\n- Create: `[1, 2, 3]` or `list(range(5))`.\n- `.append(item)`: add single item to end.\n- `.extend(iterable)`: add multiple items.\n- `.insert(index, item)`: insert at position.\n- `.pop(index)`: remove and return item at index (last if no index).\n- `.remove(value)`: remove first occurrence of value.\n- `.sort()`: sort in place. `.sort(reverse=True)` for descending.\n- `sorted(list)`: returns new sorted list.\n- List comprehension: `[x*2 for x in range(10) if x % 2 == 0]`.\n- Slice: `lst[start:end:step]`. Copy: `lst[:]`.\n- `len(lst)`, `min(lst)`, `max(lst)`, `sum(lst)`."
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"topic": "python_dicts",
|
| 78 |
+
"tags": [
|
| 79 |
+
"python",
|
| 80 |
+
"dictionary",
|
| 81 |
+
"dict",
|
| 82 |
+
"hashmap",
|
| 83 |
+
"keys",
|
| 84 |
+
"values",
|
| 85 |
+
"items"
|
| 86 |
+
],
|
| 87 |
+
"content": "Python Dictionaries:\n- Create: `{\"key\": \"value\"}` or `dict(a=1, b=2)`.\n- Access: `d[\"key\"]`. Use `d.get(\"key\", default)` to avoid KeyError.\n- Set: `d[\"key\"] = value`.\n- `.keys()`, `.values()`, `.items()` for views.\n- `for k, v in d.items():` for iteration.\n- `key in d` to check existence.\n- `.pop(key)`, `.popitem()` to remove.\n- `.update(other_dict)` to merge.\n- Dict comprehension: `{x: x**2 for x in range(5)}`.\n- `defaultdict` from collections for default values.\n- `Counter` from collections for counting."
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"topic": "algorithm_sorting",
|
| 91 |
+
"tags": [
|
| 92 |
+
"algorithm",
|
| 93 |
+
"sort",
|
| 94 |
+
"sorting",
|
| 95 |
+
"bubble",
|
| 96 |
+
"merge",
|
| 97 |
+
"quick",
|
| 98 |
+
"binary search"
|
| 99 |
+
],
|
| 100 |
+
"content": "Common Sorting Algorithms:\n- Built-in: `sorted(list)` or `list.sort()`. Uses Timsort (O(n log n)).\n- `sorted(list, key=lambda x: x[1])` for custom sort key.\n- `sorted(list, reverse=True)` for descending.\n- Binary search: `bisect_left(list, x)` from bisect module.\n- Sort by multiple criteria: `sorted(list, key=lambda x: (x.age, x.name))`.\n- Partial sort: `heapq.nsmallest(k, list)` or `heapq.nlargest(k, list)`.\n- Finding min/max with conditions: `min(list, key=func)`."
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"topic": "algorithm_recursion",
|
| 104 |
+
"tags": [
|
| 105 |
+
"algorithm",
|
| 106 |
+
"recursion",
|
| 107 |
+
"recursive",
|
| 108 |
+
"base case",
|
| 109 |
+
"stack",
|
| 110 |
+
"memoization"
|
| 111 |
+
],
|
| 112 |
+
"content": "Recursion:\n- A function that calls itself with smaller inputs.\n- Must have a BASE CASE to stop recursion (e.g., n <= 1).\n- Must make PROGRESS toward base case each call.\n- Stack limit: Python has ~1000 recursion depth limit.\n- Memoization: cache results with `@functools.lru_cache(maxsize=None)`.\n- Examples: factorial, fibonacci, tree traversal, divide-and-conquer.\n- Iterative alternative: use a stack (list) to simulate recursion.\n- Tail recursion: Python does NOT optimize tail recursion."
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"topic": "algorithm_search",
|
| 116 |
+
"tags": [
|
| 117 |
+
"algorithm",
|
| 118 |
+
"search",
|
| 119 |
+
"linear",
|
| 120 |
+
"binary",
|
| 121 |
+
"bfs",
|
| 122 |
+
"dfs",
|
| 123 |
+
"graph"
|
| 124 |
+
],
|
| 125 |
+
"content": "Search Algorithms:\n- Linear search: check each element O(n). Works on unsorted data.\n- Binary search: divide-and-conquer on sorted data O(log n). Use bisect module.\n- BFS (Breadth-First Search): uses queue, finds shortest path in unweighted graph.\n- DFS (Depth-First Search): uses stack or recursion, good for exhaustive search.\n- Dijkstra: shortest path in weighted graph. Use `heapq` for priority queue.\n- A*: heuristic-guided search for pathfinding.\n- Graph representation: adjacency list `{node: [neighbors]}` or matrix."
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"topic": "testing_basics",
|
| 129 |
+
"tags": [
|
| 130 |
+
"testing",
|
| 131 |
+
"pytest",
|
| 132 |
+
"unittest",
|
| 133 |
+
"assert",
|
| 134 |
+
"test",
|
| 135 |
+
"tdd"
|
| 136 |
+
],
|
| 137 |
+
"content": "Python Testing:\n- Use pytest: `pip install pytest`. Run with `pytest` command.\n- Test files named `test_*.py` or `*_test.py`.\n- Test functions named `test_*`.\n- Use `assert` for checks: `assert add(2, 3) == 5`.\n- pytest discovers tests automatically.\n- Fixtures: use `@pytest.fixture` for setup/teardown.\n- `pytest.raises(ExceptionType)` for testing exceptions.\n- `pytest.mark.parametrize` for running same test with multiple inputs.\n- Coverage: `pytest --cov=module` to check code coverage.\n- Test categories: normal cases, edge cases, error cases, boundary values."
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"topic": "testing_patterns",
|
| 141 |
+
"tags": [
|
| 142 |
+
"testing",
|
| 143 |
+
"mock",
|
| 144 |
+
"patch",
|
| 145 |
+
"fixture",
|
| 146 |
+
"integration",
|
| 147 |
+
"unit"
|
| 148 |
+
],
|
| 149 |
+
"content": "Testing Patterns:\n- Unit test: tests a single function/method in isolation.\n- Integration test: tests multiple components together.\n- Mock: `unittest.mock.patch` or `pytest-mock` to replace dependencies.\n- Arrange-Act-Assert: set up data, execute code, verify result.\n- Given-When-Then: BDD style of describing tests.\n- Test doubles: Dummy, Stub, Spy, Mock, Fake.\n- Coverage metrics: line coverage, branch coverage, path coverage.\n- Property-based testing: `hypothesis` library generates random inputs.\n- Snapshot testing: compare output to saved reference."
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"topic": "code_quality_linting",
|
| 153 |
+
"tags": [
|
| 154 |
+
"code quality",
|
| 155 |
+
"lint",
|
| 156 |
+
"linter",
|
| 157 |
+
"pylint",
|
| 158 |
+
"flake8",
|
| 159 |
+
"formatting"
|
| 160 |
+
],
|
| 161 |
+
"content": "Code Quality:\n- Linting: automated checking for errors and style issues.\n- flake8: checks PEP 8 style, syntax errors, complexity.\n- pylint: more thorough checking, generates quality score.\n- black: opinionated code formatter (auto-fixes formatting).\n- isort: sorts imports alphabetically.\n- mypy: static type checker for type hints.\n- ruff: fast Rust-based linter and formatter (combines flake8+isort+more).\n- pre-commit: runs checks before git commit.\n- PEP 8: 79-char lines, 4-space indent, snake_case functions, CamelCase classes."
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
"topic": "git_basics",
|
| 165 |
+
"tags": [
|
| 166 |
+
"git",
|
| 167 |
+
"version control",
|
| 168 |
+
"commit",
|
| 169 |
+
"branch",
|
| 170 |
+
"merge",
|
| 171 |
+
"clone"
|
| 172 |
+
],
|
| 173 |
+
"content": "Git Basics:\n- `git init`: initialize new repository.\n- `git clone <url>`: copy remote repository.\n- `git add <file>`: stage changes. `git add .` for all changes.\n- `git commit -m \"message\"`: save staged changes.\n- `git status`: see current state of working directory.\n- `git log`: view commit history. `git log --oneline` for compact view.\n- `git diff`: see unstaged changes. `git diff --staged` for staged changes.\n- `git branch <name>`: create branch. `git checkout <name>`: switch branch.\n- `git merge <branch>`: merge branch into current branch.\n- `git push`: upload commits to remote. `git pull`: download and merge."
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"topic": "file_io",
|
| 177 |
+
"tags": [
|
| 178 |
+
"python",
|
| 179 |
+
"file",
|
| 180 |
+
"io",
|
| 181 |
+
"read",
|
| 182 |
+
"write",
|
| 183 |
+
"csv",
|
| 184 |
+
"json",
|
| 185 |
+
"open"
|
| 186 |
+
],
|
| 187 |
+
"content": "Python File I/O:\n- Read: `with open(path) as f: content = f.read()`.\n- Read lines: `with open(path) as f: lines = f.readlines()`.\n- Write: `with open(path, 'w') as f: f.write(content)`.\n- Append: `with open(path, 'a') as f: f.write(content)`.\n- CSV: `import csv`. `csv.reader(f)` to read. `csv.writer(f)` to write.\n- JSON: `json.load(f)` to read. `json.dump(data, f)` to write. `json.dumps(obj)` to string.\n- Binary: `open(path, 'rb')` / `open(path, 'wb')`.\n- Path: use `os.path.join(dir, file)` for cross-platform paths.\n- Directory: `os.makedirs(path, exist_ok=True)`. `os.listdir(path)`.\n- Check exists: `os.path.exists(path)`. `os.path.isfile(path)`."
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"topic": "security_basics",
|
| 191 |
+
"tags": [
|
| 192 |
+
"security",
|
| 193 |
+
"injection",
|
| 194 |
+
"validation",
|
| 195 |
+
"xss",
|
| 196 |
+
"sql",
|
| 197 |
+
"sanitize"
|
| 198 |
+
],
|
| 199 |
+
"content": "Security Best Practices:\n- Input validation: NEVER trust user input. Validate type, length, format.\n- SQL injection: use parameterized queries, never string concatenation.\n- XSS (Cross-Site Scripting): escape output in HTML context.\n- eval() is DANGEROUS: use `ast.literal_eval()` for safe evaluation.\n- exec() is DANGEROUS: avoid entirely. Use restricted environments if necessary.\n- Password hashing: use bcrypt, argon2, or hashlib with salt.\n- HTTPS: always use for network communication.\n- Secret management: use environment variables, never hardcode secrets.\n- Dependency scanning: check for known vulnerabilities (Dependabot).\n- Principle of least privilege: give minimum necessary permissions."
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"topic": "security_sql_injection",
|
| 203 |
+
"tags": [
|
| 204 |
+
"security",
|
| 205 |
+
"sql",
|
| 206 |
+
"injection",
|
| 207 |
+
"parameterized",
|
| 208 |
+
"prepared"
|
| 209 |
+
],
|
| 210 |
+
"content": "SQL Injection Prevention:\n- BAD: `f\"SELECT * FROM users WHERE name = '{name}'\"` \u2014 allows injection.\n- GOOD: use parameterized queries: `cursor.execute(\"SELECT * FROM users WHERE name = ?\", (name,))`.\n- ORMs (SQLAlchemy, Django) auto-parameterize queries.\n- Escape special characters if you must build strings.\n- Use stored procedures for complex operations.\n- Validate input: reject unexpected characters.\n- Limit database permissions per application user.\n- Monitor for injection attempts in logs."
|
| 211 |
+
},
|
| 212 |
+
{
|
| 213 |
+
"topic": "design_patterns_creational",
|
| 214 |
+
"tags": [
|
| 215 |
+
"design patterns",
|
| 216 |
+
"singleton",
|
| 217 |
+
"factory",
|
| 218 |
+
"builder",
|
| 219 |
+
"prototype"
|
| 220 |
+
],
|
| 221 |
+
"content": "Creational Design Patterns:\n- Singleton: ensure class has exactly one instance. Module-level variable in Python.\n- Factory: factory function returns objects without specifying exact class.\n- Factory Method: subclass decides which class to instantiate.\n- Abstract Factory: create families of related objects.\n- Builder: separate construction from representation. Build step-by-step.\n- Prototype: clone existing objects instead of creating new ones.\n- Python-specific: use `__new__` for singleton. Use classmethods as factories."
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"topic": "python_concurrency",
|
| 225 |
+
"tags": [
|
| 226 |
+
"python",
|
| 227 |
+
"concurrent",
|
| 228 |
+
"threading",
|
| 229 |
+
"async",
|
| 230 |
+
"multiprocessing",
|
| 231 |
+
"asyncio"
|
| 232 |
+
],
|
| 233 |
+
"content": "Python Concurrency:\n- Threading: `import threading`. Thread(target=func, args=(...)). GIL limits CPU parallelism.\n- Multiprocessing: `import multiprocessing`. Process(target=func). True parallelism.\n- asyncio: `async def`, `await`, `asyncio.run()`. Cooperative multitasking for I/O.\n- concurrent.futures: ThreadPoolExecutor for threads, ProcessPoolExecutor for processes.\n- Lock: prevent race conditions. `threading.Lock()`. Use `with lock:`.\n- Queue: thread-safe queue. `queue.Queue()`. For producer-consumer patterns.\n- Use asyncio for: web servers, API calls, file I/O operations.\n- Use multiprocessing for: CPU-heavy computations, data processing."
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"topic": "web_requests",
|
| 237 |
+
"tags": [
|
| 238 |
+
"web",
|
| 239 |
+
"http",
|
| 240 |
+
"requests",
|
| 241 |
+
"api",
|
| 242 |
+
"rest",
|
| 243 |
+
"get",
|
| 244 |
+
"post"
|
| 245 |
+
],
|
| 246 |
+
"content": "HTTP Requests in Python:\n- `import requests`. Install: `pip install requests`.\n- GET: `r = requests.get(url, params={\"key\": \"value\"})`.\n- POST: `r = requests.post(url, json={\"key\": \"value\"})`.\n- Response: `r.status_code`, `r.json()`, `r.text`, `r.headers`.\n- Timeout: `requests.get(url, timeout=5)` to avoid hanging.\n- Error handling: `r.raise_for_status()` or check `r.status_code`.\n- Headers: `requests.get(url, headers={\"Authorization\": \"Bearer token\"})`.\n- Session: `s = requests.Session()` for persistent connections and cookies.\n- Authentication: `requests.get(url, auth=(\"user\", \"pass\"))`."
|
| 247 |
+
},
|
| 248 |
+
{
|
| 249 |
+
"topic": "data_structures_advanced",
|
| 250 |
+
"tags": [
|
| 251 |
+
"data structures",
|
| 252 |
+
"heap",
|
| 253 |
+
"queue",
|
| 254 |
+
"stack",
|
| 255 |
+
"tree",
|
| 256 |
+
"graph",
|
| 257 |
+
"hash"
|
| 258 |
+
],
|
| 259 |
+
"content": "Advanced Python Data Structures:\n- Heap (min): `import heapq`. `heapq.heappush(heap, item)`. `heapq.heappop(heap)`.\n- Heap (max): push negative values, or use custom key with wrapper.\n- Queue (FIFO): `from collections import deque`. `d.append()` / `d.popleft()`.\n- Stack (LIFO): use list. `.append()` / `.pop()`.\n- Priority Queue: `from queue import PriorityQueue` (thread-safe) or heapq.\n- Default dict: `from collections import defaultdict(lambda: 0)`.\n- Ordered dict: `from collections import OrderedDict` (Python 3.7+ dicts are ordered).\n- Named tuple: `from collections import namedtuple`. `Point = namedtuple('Point', ['x', 'y'])`.\n- ChainMap: combine multiple dicts.\n- Counter: `from collections import Counter`. `Counter(list).most_common(3)`."
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"topic": "tool_call_format",
|
| 263 |
+
"tags": [
|
| 264 |
+
"tool",
|
| 265 |
+
"json",
|
| 266 |
+
"format",
|
| 267 |
+
"nanobot",
|
| 268 |
+
"api",
|
| 269 |
+
"function calling"
|
| 270 |
+
],
|
| 271 |
+
"content": "Tool Call JSON Format:\n- Write file: {\"tool\": \"fs\", \"action\": \"write\", \"path\": \"filename.py\", \"content\": \"code here\"}\n- Read file: {\"tool\": \"fs\", \"action\": \"read\", \"path\": \"filename.py\"}\n- List dir: {\"tool\": \"fs\", \"action\": \"list\", \"path\": \"directory\"}\n- Check exists: {\"tool\": \"fs\", \"action\": \"exists\", \"path\": \"filename.py\"}\n- Delete: {\"tool\": \"fs\", \"action\": \"delete\", \"path\": \"filename.py\"}\n- Create dir: {\"tool\": \"fs\", \"action\": \"mkdir\", \"path\": \"directory\"}\n- Compile check: {\"tool\": \"compile\", \"path\": \"filename.py\"}\n- Run tests: {\"tool\": \"test\", \"path\": \"directory\"}\n- Search code: {\"tool\": \"search\", \"query\": \"pattern\", \"path\": \".\", \"ext\": \".py\"}\n- Run command: {\"tool\": \"shell\", \"cmd\": \"command string\"}\n- Git init: {\"tool\": \"git\", \"action\": \"init\", \"path\": \".\"}\n- Git commit: {\"tool\": \"git\", \"action\": \"commit\", \"message\": \"commit msg\"}\n- Done: {\"tool\": \"done\"}\n\nAlways emit JSON on a single line. After the tool call, include THOUGHT: and RESULT: on new lines."
|
| 272 |
+
}
|
| 273 |
+
]
|