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 |
|---|---|---|---|---|---|---|---|---|
6b425d65 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
a4df218c | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Save data thành JSON file. | Sử dụng khi cần đọc toàn bộ file vào memory. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
3fb46fa2 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
314c38e9 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
770cc0cf | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
135df398 | 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 | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
93c79462 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
8297ea2c | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
4bc6dc02 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
848552e8 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
021411ef | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
be0cad94 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
57fbf902 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
41a6f323 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
b2f9062a | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
b2229c20 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
3a5d0f3c | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
051c0adf | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
96783cef | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Hàm này đọc nội dung của file và trả về dưới dạng string. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
54e71136 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
000d3d07 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
4bf5a32e | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
58c8bb6c | 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 | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
b5e53f2b | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
f1ef172a | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
3cc89449 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
a3fdabe8 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
c44e3dcd | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
4a32b09c | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
8a038bf2 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
43aaf484 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
d17217a1 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
b3372d25 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
aec2a58c | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Ghi nội dung vào file. Context manager tự động đóng file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
91e791f9 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
40dd7396 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
9e7ea193 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
76b489d1 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
98462bcd | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
ad64896e | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
0a844c6e | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Xử lý danh sách: strip spaces, convert to lowercase, filter empty. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
19b39aa7 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
af24c890 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
a85f5e6f | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
45c39877 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
b08af406 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
dfa799b5 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
f68e2bbe | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
a5f91b94 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
e9a276a5 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
a4083c01 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
cc73171c | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
dee49ef2 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
ea555acb | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
b4b596a7 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
1c4e8dbd | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
0e236264 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
f0b65973 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
9007e302 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
8a590828 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
29a1e272 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
c6258ec2 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
6a99b0fa | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
f65ac1f5 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
6f86c69c | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
8f486e62 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
acc2fb18 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
ce857efc | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
e6f32a73 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
09dcd01e | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
ed02a301 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
47af82a0 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Đảo ngược thứ tự các từ trong text. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
5745cabb | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
5120795e | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
be151e0e | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Đảo ngược thứ tự các từ trong text. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
26bf652e | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Đảo ngược thứ tự các từ trong text. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
68649875 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
01832122 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
eb164506 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
c346cfcd | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
5b65a6c0 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
f0adc732 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
e43063c6 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
a793e318 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Đảo ngược thứ tự các từ trong text. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
4f2d554c | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
3784b51e | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
75a34732 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
e99754cc | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
618320c9 | 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
17f49e2d | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
614e4d7d | 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
243f89f3 | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
13f119f7 | 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
94b00432 | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
f5ae7040 | 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
3b3ae922 | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
49af2163 | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
4b278167 | 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
b916c501 | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
5030a63a | # 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ự. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"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.