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
4e3ac010
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
006f15df
# 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.
Try-except pattern cho error handling.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
22e0bdc4
# 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.
Try-except pattern cho error handling.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
da0c01e6
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
4ce18ca0
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.
Try-except pattern cho error handling.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
bafdc501
# 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.
Try-except pattern cho error handling.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
dec7c175
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
Try-except pattern cho error handling.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
e541d9fa
# 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.
Try-except pattern cho error handling.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
a88141b0
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.
Try-except pattern cho error handling.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
40da89b2
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
Try-except pattern cho error handling.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a5fa9e2d
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
Try-except pattern cho error handling.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
46615de0
# 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.
Try-except pattern cho error handling.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
cb8b6d4d
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.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
ee515a27
# 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.
Try-except pattern cho error handling.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
586837d0
# 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.
Try-except pattern cho error handling.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
be67daa0
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.
Try-except pattern cho error handling.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
89da907a
# 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.
Try-except pattern cho error handling.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
2c908389
# 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.
Try-except pattern cho error handling.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
756e619d
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đảo ngược thứ tự các từ trong text.
Try-except pattern cho error handling.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
b1fd1449
# 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.
Try-except pattern cho error handling.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
895e7244
# 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.
Try-except pattern cho error handling.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
1627e42e
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.
Try-except pattern cho error handling.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
6e6bc93b
# 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ự.
Try-except pattern cho error handling.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d2dbdaa0
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ự.
Try-except pattern cho error handling.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
e89a919b
# 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ự.
Try-except pattern cho error handling.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
1e4ba1e5
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ự.
Try-except pattern cho error handling.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
397802d8
# 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ự.
Try-except pattern cho error handling.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
afbc1b2a
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ự.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
6512ae1b
# 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ự.
Try-except pattern cho error handling.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
17807c96
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ự.
Try-except pattern cho error handling.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
cce66db0
# 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ự.
Try-except pattern cho error handling.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
8bd98ed9
# 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ự.
Try-except pattern cho error handling.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
629d62c6
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ự.
Try-except pattern cho error handling.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
9c2b76c3
# 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ự.
Try-except pattern cho error handling.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
41d69f63
# 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ự.
Try-except pattern cho error handling.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
f1824d6a
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đếm tần suất xuất hiện của mỗi ký tự.
Try-except pattern cho error handling.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
312edb96
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Đếm tần suất xuất hiện của mỗi ký tự.
Try-except pattern cho error handling.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
60080a1b
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Đếm tần suất xuất hiện của mỗi ký tự.
Try-except pattern cho error handling.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
a9244535
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Đếm tần suất xuất hiện của mỗi ký tự.
Try-except pattern cho error handling.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
baa9e2b6
# File I/O def read_file(path): with open(path) as f: return f.read()
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
84800aa8
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
1ffa7c98
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
429a138e
def group_by_key(items, key): result = {} for item in items: k = item.get(key) if k not in result: result[k] = [] result[k].append(item) return result
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
b4bacd5a
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
566eac41
def count_chars(text): return {c: text.count(c) for c in set(text)}
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
5de20486
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
fc028e10
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
5e895f60
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
9b2438a8
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
5c6e5607
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
a91f665e
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
479b8df3
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
ca1bd556
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
fc24b39e
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
17b22042
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
cedcd199
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Làm phẳng list nested thành flat list.
Try-except pattern cho error handling.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
59d73ee2
# File I/O def read_file(path): with open(path) as f: return f.read()
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
b7dee62b
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
aa8f414c
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
46e84b3e
def group_by_key(items, key): result = {} for item in items: k = item.get(key) if k not in result: result[k] = [] result[k].append(item) return result
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
9239185a
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a48f4f14
def count_chars(text): return {c: text.count(c) for c in set(text)}
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
79f49c80
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
80a3b47a
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
b793932c
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
2d852a44
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
a4d1735a
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
79142aa9
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
e198fb38
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
70a72f0b
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
eed87c66
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
743cd262
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
f5afc3cf
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Gộp nhiều dictionaries thành một.
Try-except pattern cho error handling.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b019e01b
# File I/O def read_file(path): with open(path) as f: return f.read()
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
afe03292
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
5e41da20
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
4d2441db
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
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
f7ab4a6d
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
575db0f7
def count_chars(text): return {c: text.count(c) for c in set(text)}
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
07959cb9
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
61371f55
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
dd14d2df
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
835eca89
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7aea692b
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
06dde094
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
c754bfa0
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
ba68eb51
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
c8d2de57
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ce1035fc
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
e60c40a4
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Chuyển đổi string thành int, trả về default nếu lỗi.
Try-except pattern cho error handling.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
aba26d17
# File I/O def read_file(path): with open(path) as f: return f.read()
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
99a0b1a9
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
9db1b0ad
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
e5b92263
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
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
e8251341
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b2dccc5a
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
c7d6715a
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
98a4501f
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
21fe86c9
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
53625412
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Try-except pattern cho error handling.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]