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
8c9d8f7a
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Extract emails từ text dùng regex pattern.
Merging dictionaries là common trong config management.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
3a479b0f
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Extract emails từ text dùng regex pattern.
Merging dictionaries là common trong config management.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
cad6ec38
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Extract emails từ text dùng regex pattern.
Merging dictionaries là common trong config management.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
ef872a01
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
c75c0c9c
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
3f45dddc
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
c7701517
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.
Merging dictionaries là common trong config management.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
36154196
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
00598c4a
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
5ad7e7cf
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
e6dbbb6d
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.
Merging dictionaries là common trong config management.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
827df0f5
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
ec925f25
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
8502952f
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.
Merging dictionaries là common trong config management.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
5071e379
# 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.
Merging dictionaries là common trong config management.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
3f8b1f9b
# 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.
Merging dictionaries là common trong config management.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1e9daae1
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
41c706d7
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
4930e837
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
0aba8a92
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Merging dictionaries là common trong config management.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
273b60b3
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
7a3720b2
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
cd6601ea
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
7cea2512
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.
Merging dictionaries là common trong config management.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
2656c71c
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
dc63bdf6
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
a963f87f
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
15abbbd3
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
14f6d2e1
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
0ba98a51
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
e854f727
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.
Merging dictionaries là common trong config management.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
8951f294
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
c0b29aec
# 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.
Merging dictionaries là common trong config management.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a4519622
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6b4decd4
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e9fe0100
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
9810266a
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
Merging dictionaries là common trong config management.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
c5c98013
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
43c241b3
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.
Try-except pattern cho error handling.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
bebb930b
# 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.
Try-except pattern cho error handling.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
04bcb158
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.
Try-except pattern cho error handling.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
59783742
# 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.
Try-except pattern cho error handling.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
ba8c8e6f
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.
Try-except pattern cho error handling.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
d5fb05b8
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
bdbb0255
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.
Try-except pattern cho error handling.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
88b68e88
# 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.
Try-except pattern cho error handling.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
777e5b78
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
dd38ab97
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.
Try-except pattern cho error handling.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
a8b00d98
# 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.
Try-except pattern cho error handling.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
1d5812ca
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a89dc210
# 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.
Try-except pattern cho error handling.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
bf7db7f7
# 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.
Try-except pattern cho error handling.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ebbfb36f
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
80f19488
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.
Try-except pattern cho error handling.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
418c39af
# 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.
Try-except pattern cho error handling.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
07d52902
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.
Try-except pattern cho error handling.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
37c1c172
# 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.
Try-except pattern cho error handling.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
fc644be5
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.
Try-except pattern cho error handling.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
a46d62b5
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
Try-except pattern cho error handling.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
58b9d9fc
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.
Try-except pattern cho error handling.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
514d5714
# 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.
Try-except pattern cho error handling.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
80c6aed1
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.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
da2bd0d7
# 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.
Try-except pattern cho error handling.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
1137054a
# 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.
Try-except pattern cho error handling.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
b9000a20
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.
Try-except pattern cho error handling.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
bcb227a6
# 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.
Try-except pattern cho error handling.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
cf213d81
# 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.
Try-except pattern cho error handling.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a6d1e393
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
10a13f24
# 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.
Try-except pattern cho error handling.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
6aa56d32
# 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.
Try-except pattern cho error handling.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
a4f88e07
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.
Try-except pattern cho error handling.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
79a920da
# 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.
Try-except pattern cho error handling.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
7ee2810f
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.
Try-except pattern cho error handling.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
fdbee936
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
e1d91de8
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.
Try-except pattern cho error handling.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
3a7338f9
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Try-except pattern cho error handling.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
241c925f
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.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
61fe6aa0
# 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.
Try-except pattern cho error handling.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
bdb6d6a4
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.
Try-except pattern cho error handling.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
492b953e
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
38f87b08
# 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.
Try-except pattern cho error handling.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
d76e49c8
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.
Try-except pattern cho error handling.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
1ab8ffc0
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
f3b01f66
# 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.
Try-except pattern cho error handling.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7444dd3c
# 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.
Try-except pattern cho error handling.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
8c5e5ddc
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
06433168
# 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.
Try-except pattern cho error handling.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
78d75e84
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.
Try-except pattern cho error handling.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
68947a31
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
f81e2cf5
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.
Try-except pattern cho error handling.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
9ba8d1a4
# 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.
Try-except pattern cho error handling.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
6f1af19f
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.
Try-except pattern cho error handling.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
cf803222
# 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.
Try-except pattern cho error handling.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b51c91ef
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.
Try-except pattern cho error handling.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
2c79c99a
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3217410a
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.
Try-except pattern cho error handling.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
f6d383cf
# 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.
Try-except pattern cho error handling.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
d754d37e
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
b39a2d34
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.
Try-except pattern cho error handling.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
03b3bf13
# 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.
Try-except pattern cho error handling.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]