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
9c28770f
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
af31d8aa
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
3fecf830
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
2983c29b
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
4b5569b1
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
3cf393de
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
28ece5df
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
b11f28fb
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6ab95b74
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
5a099476
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
5d7f40be
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
eba4f44f
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
4120e182
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8496b586
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
8f1be12e
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
8941d6e0
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b28c3e40
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b4bfcb4e
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d84faa93
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0001780b
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
df0eb8ee
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
0ad71ace
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
7f31bb94
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
d388e162
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
d279f16c
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
471cd71e
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
f70a378d
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
1585726d
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
a6b4ca33
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
1f50430a
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
87264e3e
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
33aff0e9
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
dbe6b0d0
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
093493e3
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
5a7071e9
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
de5994df
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
a00d645a
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
d74de3b2
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
753476be
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
1b14c331
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
87651964
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3f64599b
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
a9c185db
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
0645ce26
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
b302b61a
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
b0f78049
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
19a9011f
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8cb60d39
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
b5259418
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
8aae5c04
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
17ccf724
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
5fddc474
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
4ab631c6
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0b44a231
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
48d8665b
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
9ea5995e
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
8ab6329d
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
49fbaa22
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
8d958fde
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
28e157e4
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
3b5782d1
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
c36e8d81
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
e283bf3e
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
1137272b
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
520b5044
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
1251e91e
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
5a70fa95
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
d5af4a00
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
73a51181
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
574c2177
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
dc44c863
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
0b2a224c
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
247a68f5
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
d3453a41
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
8138f100
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3f8bb481
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
48bdf938
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
a891c541
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7a4a65a0
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
70a6fb5a
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
3f5002c2
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
0a1c614f
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
8507a151
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
fc4d0926
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
43c13ef8
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
8082215f
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3db6420a
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
42bd2928
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
a884d1c3
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
e4db458a
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b048efab
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
738714b9
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
e3f51ccc
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
4bf23dda
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
a9a9f3a2
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
63158b5c
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
09a771fe
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
61ac8aa9
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
25f57646
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
5cc6a635
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]