id stringlengths 8 8 | code stringclasses 17
values | explanation stringclasses 17
values | context stringclasses 17
values | language stringclasses 1
value | difficulty stringclasses 3
values | tags listlengths 2 2 | version stringclasses 1
value | keywords listlengths 3 3 |
|---|---|---|---|---|---|---|---|---|
2fb1a6d4 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
7ec5590f | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
d9bb4d98 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
ce2f850e | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
0fefe21a | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
dcd09a31 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
a435376b | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
2409bb9c | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
158f5510 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
65bd03e4 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
c049a805 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
8e648f3c | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
84f366e8 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
26e7a7f8 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
7075fc1c | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
77da5a5e | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
dd8a8b6c | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Base class cơ bản. **kwargs để flexible initialization. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
33571900 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
f8784e34 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
2e398cb5 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
fe09e32a | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
c0519d15 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
db96ec97 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
c3afeead | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
eb3b4bc6 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
9c05041f | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
80871eaf | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
eaaa166d | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
1eb3dac2 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
2cedb4a0 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
fb1fdcc5 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
a2b1f3d6 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
5fd97781 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
5eb15e11 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Decorator log_calls ghi lại mỗi lần function được gọi. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
0f5fd1b1 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
0ee34025 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
6fbcc910 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
7f3e3d08 | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
ad31a553 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
3bef8640 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
1b22f812 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
1c4f257e | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
c3854d44 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
d161d6c0 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
4a7fb713 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
b356d523 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
adea34a9 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
4e4dacb3 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
fde52d25 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
87ea5316 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
fcf94312 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Fetch data từ API endpoint. Trả về JSON. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
26947946 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
facfd2d1 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
5baafbdf | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
447a2794 | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
5e9683f3 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
c5bd89ed | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
16573daa | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
c86ffa4a | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
997a4e45 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
858b59fb | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
ba14e9f9 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
68926ef7 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
0014d5af | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
c226bf76 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
5a510ada | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
9266894b | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
97d5c049 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Extract emails từ text dùng regex pattern. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
efe7b577 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
28c4f783 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
2221870d | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
ac15258e | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
55e43992 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
de25ee72 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
4b111366 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
e672596d | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
28a3e1ca | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
98d500ae | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
e303939a | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
ab26c99f | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
09682b46 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
c7fa80fd | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
365cafa2 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
47efd48b | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
4574f858 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Load JSON từ file. Trả về parsed object. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
dd06b787 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
508fd5b0 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
edc1f58e | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
ca8766f8 | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
8afb8232 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
d533593b | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
73b1fb44 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
448591bf | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
be7c0d95 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
01e18d17 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
21b217dc | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
22a60a10 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
f91e9546 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
2983c918 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
35c6599d | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.