Skip to content

Commit 2d5ec25

Browse files
Manual review of builtin functions: float-bytes
1 parent 419b44e commit 2d5ec25

3 files changed

Lines changed: 0 additions & 167 deletions

File tree

docs/builtins/bytes_func.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -186,58 +186,6 @@ data = bytes(message, "utf-8") # O(n)
186186
# socket.send(data) # Sends bytes
187187
```
188188

189-
## Practical Examples
190-
191-
### HTTP Request
192-
193-
```python
194-
# O(n) - build request
195-
def build_request(method, path, body):
196-
request = f"{method} {path} HTTP/1.1\r\n"
197-
request += f"Content-Length: {len(body)}\r\n\r\n"
198-
request += body
199-
200-
return bytes(request, "utf-8") # O(n)
201-
202-
req = build_request("GET", "/api", "")
203-
```
204-
205-
### Cryptography
206-
207-
```python
208-
# O(n) - encode for hashing
209-
import hashlib
210-
211-
text = "password123"
212-
hashed = hashlib.sha256(bytes(text, "utf-8")).hexdigest() # O(n)
213-
```
214-
215-
### Base64 Encoding
216-
217-
```python
218-
# O(n) - convert to bytes then encode
219-
import base64
220-
221-
text = "Hello, World!"
222-
text_bytes = bytes(text, "utf-8") # O(n)
223-
encoded = base64.b64encode(text_bytes) # O(n)
224-
# b'SGVsbG8sIFdvcmxkIQ=='
225-
```
226-
227-
### Binary Protocol
228-
229-
```python
230-
# O(n) - create binary message
231-
def create_packet(header, payload):
232-
header_bytes = bytes(header, "utf-8") # O(h)
233-
payload_bytes = bytes(payload, "utf-8") # O(p)
234-
235-
# Combine (simplified)
236-
return header_bytes + payload_bytes # O(h+p)
237-
238-
packet = create_packet("HEADER", "DATA")
239-
```
240-
241189
## Edge Cases
242190

243191
### Empty String

docs/builtins/float_func.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -158,58 +158,6 @@ float("3.14") # O(4) - handles decimals
158158
# float() is more flexible
159159
```
160160

161-
## Practical Examples
162-
163-
### CSV Parsing
164-
165-
```python
166-
# O(n * m) - parse CSV with float values
167-
csv_line = "1.5,2.7,3.14,10.0"
168-
169-
def parse_csv_floats(line):
170-
return [float(x) for x in line.split(",")] # O(n)
171-
172-
values = parse_csv_floats(csv_line)
173-
# [1.5, 2.7, 3.14, 10.0]
174-
```
175-
176-
### Decimal Arithmetic
177-
178-
```python
179-
# O(n) - string parsing for precision
180-
def money_to_float(money_str):
181-
# "$10.50" -> 10.5
182-
cleaned = money_str.replace("$", "").strip()
183-
return float(cleaned) # O(n)
184-
185-
prices = ["$10.50", "$25.00", "$5.99"]
186-
values = [money_to_float(p) for p in prices]
187-
# [10.5, 25.0, 5.99]
188-
```
189-
190-
### Statistics Calculation
191-
192-
```python
193-
# O(n) - convert and compute
194-
def calculate_average(data_str):
195-
values = [float(x) for x in data_str.split(",")] # O(n)
196-
return sum(values) / len(values) # O(n)
197-
198-
avg = calculate_average("10.5,20.3,15.7") # 15.5
199-
```
200-
201-
### Matrix/Vector Operations
202-
203-
```python
204-
# O(n) - convert all elements
205-
def parse_vector(vector_str):
206-
# "1.5 2.7 3.14" -> [1.5, 2.7, 3.14]
207-
return [float(x) for x in vector_str.split()] # O(n)
208-
209-
vec = parse_vector("1.5 2.7 3.14")
210-
magnitude = sum(x**2 for x in vec) ** 0.5
211-
```
212-
213161
## Edge Cases
214162

215163
### Empty String

docs/builtins/str_func.md

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -188,69 +188,6 @@ s = f"{x} and {y}"
188188
# All have similar complexity
189189
```
190190

191-
## Practical Examples
192-
193-
### Debugging Output
194-
195-
```python
196-
# O(n) - convert all values
197-
def debug_dict(data):
198-
for key, value in data.items():
199-
print(f"{key}: {str(value)}")
200-
201-
data = {"a": 1, "b": [1, 2, 3], "c": {"nested": True}}
202-
debug_dict(data)
203-
```
204-
205-
### CSV Export
206-
207-
```python
208-
# O(n * m) - n rows, m columns
209-
def csv_row(values):
210-
return ",".join(str(v) for v in values) # O(m)
211-
212-
rows = [
213-
[1, 2, 3],
214-
[4, 5, 6],
215-
[7, 8, 9]
216-
]
217-
218-
csv_output = "\n".join(csv_row(row) for row in rows)
219-
# O(n * m) total
220-
```
221-
222-
### JSON Preparation
223-
224-
```python
225-
# O(n) - convert values to strings
226-
def prepare_json(data):
227-
result = {}
228-
for key, value in data.items():
229-
if isinstance(value, (int, float)):
230-
result[key] = str(value)
231-
else:
232-
result[key] = value
233-
return result
234-
235-
data = {"count": 42, "price": 19.99, "name": "Item"}
236-
prepared = prepare_json(data)
237-
```
238-
239-
### Configuration String
240-
241-
```python
242-
# O(n) - build configuration
243-
def build_config_string(config_dict):
244-
items = []
245-
for key, value in config_dict.items():
246-
items.append(f"{key}={str(value)}")
247-
return "; ".join(items) # O(n)
248-
249-
config = {"timeout": 30, "retries": 3, "debug": True}
250-
config_str = build_config_string(config)
251-
# "timeout=30; retries=3; debug=True"
252-
```
253-
254191
## Edge Cases
255192

256193
### None

0 commit comments

Comments
 (0)