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 |
|---|---|---|---|---|---|---|---|---|
0fc8cd6b | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Ghi nội dung vào file. Context manager tự động đóng file. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
cc8b2f16 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Ghi nội dung vào file. Context manager tự động đóng file. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
62d75284 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
3673d7a2 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
dfbe8e72 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
04b6d1e1 | 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 | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
00a3902b | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
f3890e12 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
7faa8486 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
09f52e30 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
40bc7d5c | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
88d97454 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
84429e43 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
6e5ab583 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
583cf46e | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
c1339024 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
93f77939 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
92e251b8 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
9166cb40 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
b2b0a02a | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
5939815f | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
e0c3034e | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
1d082aba | 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 | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
2348d002 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
5f4cf4d3 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
ec2260c9 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
34405907 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
dcd1747f | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
942f8222 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
80c22226 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
3284e75c | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
5a085d94 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
90c0487b | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
124f5ecd | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
42869520 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
aecfb287 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Nhóm items theo key. Tạo dictionary với key là group, value là list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
3f097466 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
ac27f77f | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
f5a2ffa1 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
aee8fc76 | 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 | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
098a14da | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
93eabed2 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
8a849a58 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
f0cdd9d7 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
6ed05433 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
e4b5f0a6 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
f9636c78 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
2439c0be | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
644a3708 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
871850c5 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
28249d20 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
715f8c38 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
90f6c1ba | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Đảo ngược thứ tự các từ trong text. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
68f55a7d | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
273f89ca | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
413951bd | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
53a159df | 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 | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
850935d5 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
8351fbf2 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
89c28b6b | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
c18444a7 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
395814bb | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
01f2e312 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
54658341 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
0fb4d743 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
f4b97fe3 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
e18005e0 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
27c5d3f2 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
99a86c03 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
0a9f8b71 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Đếm tần suất xuất hiện của mỗi ký tự. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
00021443 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
bcc039f5 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
a883792b | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
785b16cc | 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 | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
4b973476 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
4ce2ecfd | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
6a4a3b7d | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
7be56ccd | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
e054d372 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
fcda9cb4 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
e8667b0e | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
ebd40f19 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
1d5a210a | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
abe38deb | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
f204cb4c | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
57480866 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
49b6fb5b | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Làm phẳng list nested thành flat list. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
135f4415 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
8bd353eb | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
ab00952b | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
b75c66b1 | 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 | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
7025a6a2 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
bac6ce8c | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
0547e51d | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
284511eb | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
07e7eca2 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
4c33ded9 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
280c9ca0 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
d7a261f8 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
5dcd2a56 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Gộp nhiều dictionaries thành một. | Decorators enhance function behavior mà không modify source. | python | advanced | [
"decorator",
"function"
] | 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.