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
622988d8
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
44a44159
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
6c4f9851
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
f3425aad
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
9cf73227
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
4eb943d5
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1d77a515
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
d4c515c6
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9ff94167
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
fa798e16
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
f1a73332
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
e7053fbc
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
43790943
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
0c7fe1a5
def group_by_key(items, key): result = {} for item in items: k = item.get(key) if k not in result: result[k] = [] result[k].append(item) return result
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
7d55c910
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
00df7f0d
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
9462addd
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
fb485e80
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
0966559b
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
c6457975
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0fb582ed
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
dca6785b
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
38deebdf
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
0c22fe7d
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
bdfc04ce
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
82a058b8
# 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
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
478d3bad
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
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
474e724e
# 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
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
1d2ea5b6
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
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
aff7324b
# 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
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
c1c4b7e3
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
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
f2fe2754
# 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
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
ed85cd88
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
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
b53934df
# 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
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
283f6592
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
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
953067ed
# 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
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
32fb606b
# 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
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
1f7c620e
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
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
cc8346cc
# 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
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
d0062803
# 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
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
24a88b66
# 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
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
eea9613c
# 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
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
89f92d04
# 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
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
ad7123da
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
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4a71d948
# 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
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
4d22455f
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
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d3c36dcd
# 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
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
0d40b59b
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
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
f1472f60
# 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
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
90914b5f
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
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
90f1d46e
# 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
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3c61a531
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
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
d15a24c5
# 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
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
c03badd0
# 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
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
5d498cdc
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
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ebda8e02
# 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
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
aac8955d
# 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
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
0435cdd8
# 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
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
400f89ed
# 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
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
0d389b00
# 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
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
53bf6b27
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
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
f2058989
# 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
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
c43a8ada
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
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
9be78268
# 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
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
cdff1938
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
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
d2f08ca4
# 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
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
fac21f07
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
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
b8d9e43e
# 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
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
0336df0f
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
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
9c7ac222
# 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
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
b68a7041
# 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
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
252ab846
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
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
646c5b9a
# 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
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
6b184887
# 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
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
e18dda08
# 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
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
59030629
# 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
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ba42d88c
# 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
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
a939ce07
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
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
e5eeac01
# 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
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
8de4d4e9
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
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0928fe27
# 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
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
045f6674
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
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
58082e12
# 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
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
8d6468a8
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
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
9453d10c
# 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
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
e40ebd41
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
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
00ddd5c6
# 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
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
d758aaa7
# 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
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
76c645d8
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
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d6be4d8c
# 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
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
46633b0d
# 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
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
4f96a2e6
# 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
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
9bd097a2
# 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
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
52969d0c
# 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
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
c20e37a5
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
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
777deef6
# 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
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
13a22ec3
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
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
eb9e61d0
# 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
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
33bbf65a
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
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
2d66bcdb
# 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
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]