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
688cada5
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Try-except pattern cho error handling.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
ccd658c8
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Try-except pattern cho error handling.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
e1333644
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.
Try-except pattern cho error handling.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
b2828e59
# 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.
Try-except pattern cho error handling.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
7f50805e
# 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.
Try-except pattern cho error handling.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
5c5e8b05
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Try-except pattern cho error handling.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
fb6d1f2e
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Try-except pattern cho error handling.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
41871b78
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Try-except pattern cho error handling.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
650ef8ce
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Try-except pattern cho error handling.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
571f1078
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Try-except pattern cho error handling.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
0f13ea16
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
Try-except pattern cho error handling.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
bb6c0cdb
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
Try-except pattern cho error handling.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
c3a40f82
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.
Try-except pattern cho error handling.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
fdbfa4b1
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
Try-except pattern cho error handling.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
ad61f390
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
Try-except pattern cho error handling.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
8e70e01b
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
Try-except pattern cho error handling.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
0450042c
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
Try-except pattern cho error handling.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
ca192117
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
Try-except pattern cho error handling.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
06d209c7
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
Try-except pattern cho error handling.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
eec238f1
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.
Try-except pattern cho error handling.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
42bc52b6
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
Try-except pattern cho error handling.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
a9300582
# 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.
Try-except pattern cho error handling.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
4db2eed5
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
Try-except pattern cho error handling.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
3dfc5212
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
Try-except pattern cho error handling.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
7896c692
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
Try-except pattern cho error handling.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
4a20ee37
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
Try-except pattern cho error handling.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b4fe823c
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
a2660807
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
13716308
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
daa70a38
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
b57f729f
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
92c9f625
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
4143dc96
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
25031939
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
45a09e68
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
fac7b770
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0054995d
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
87b3be28
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
e40cc3bd
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a5c9e613
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
fe71fe14
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
281e9d01
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
2695fb68
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
e9e713d0
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
ce68e021
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
476d2d40
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
2fa46b43
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
74715e03
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
d988f280
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
6dad6980
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
f66b09f6
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
3851a472
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
df712839
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
e522eaf5
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
2c9e79fd
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
83af3e44
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
6eaf3851
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
125d2daf
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
1b9483ec
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
d32249ff
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
5ef81b24
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3ce24509
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
53fe0f30
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
e543439e
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
ff24a0c7
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
9add0e95
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
41e456c0
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
f66cde78
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
000bffc1
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
66582612
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
c17d84ba
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
90b4efa1
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
2032b9be
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
359bccd6
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
71fa6d79
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
f8530933
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
bbfb2e38
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
dd5b91fb
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3c20fc50
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
c144f360
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
a1498ea8
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
d5049372
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
6b032462
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
79ecd1da
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
72d8ad61
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
23b4e281
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
46cc7fb3
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
169dde87
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ee86f39b
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
dc268df0
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1e260979
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6a96416d
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
617cf203
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
02318283
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
93cf74b0
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
48a27fc2
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
ec237944
# 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.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
f7438e5e
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.
Recursion là important concept nhưng cần cẩn thận performance.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
efc9b1a9
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
Recursion là important concept nhưng cần cẩn thận performance.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
e692b459
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
Recursion là important concept nhưng cần cẩn thận performance.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]