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
9a34f65a
# 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ự.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
eb488837
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ự.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
2eb5924a
# 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.
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" ]
20d289b8
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Làm phẳng list nested thành flat list.
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" ]
41f8e3f7
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
1a7ee034
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
59d172c7
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Làm phẳng list nested thành flat list.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a34ac9f8
def count_chars(text): return {c: text.count(c) for c in set(text)}
Làm phẳng list nested thành flat list.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
9caa00a3
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
b5e08e4c
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
74560509
# 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.
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" ]
360ef7a0
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
4cdd6c25
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
8ffc4944
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
c6735f5b
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7a06cb2d
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Làm phẳng list nested thành flat list.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
2ef11e42
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
766604b1
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
28dfefe4
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
742cd95c
# File I/O def read_file(path): with open(path) as f: return f.read()
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
32322c91
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
f9e8209c
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
02b6f55c
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
cbd104cc
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
d6c77a6a
def count_chars(text): return {c: text.count(c) for c in set(text)}
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
02f1c6b3
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
4aebf2f7
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
f3745188
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
5353bf02
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
9da56cb1
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
f2636101
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
e877347b
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
29535532
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
da284090
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
8691fdf3
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
a1ed39e2
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Gộp nhiều dictionaries thành một.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4fe0e596
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
230e4c10
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
aae711eb
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
5c5e43f8
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
03596603
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
06aca184
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
f2ce8ab8
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5def4d14
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6b2a3728
# 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.
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" ]
8e8a1112
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
2b80c363
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d02e6b5d
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
ee7fbd49
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
24e9c213
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
5624ee39
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
c47775db
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
2d492cd0
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
ed2d9db2
# 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.
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" ]
4e531958
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fibonacci recursive. Chậm nhưng minh họa recursion.
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" ]
5a1d3dd8
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
66ed9341
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
ec047edc
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
1a12b6e7
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
2edce77d
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
14cdd491
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
a2fe6f41
# 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.
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" ]
1de4c888
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
64c53401
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d7d7735d
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
76fab3b8
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
c0874927
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
95d35eeb
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
99f7b53c
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
1c4d87a4
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
d622d2d7
# File I/O def read_file(path): with open(path) as f: return f.read()
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
6b18d7ec
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d017a0a4
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
b57e1534
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
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
6585df54
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
9c362c63
def count_chars(text): return {c: text.count(c) for c in set(text)}
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
1691d2d8
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
735ab1dc
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
f06cf8f9
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
c89f20d2
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
30ba709b
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
202a0a88
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
17c4af4d
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
01899bec
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
21cb35ad
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
4a3ff2d4
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
9f0f1457
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
9bd29b0f
# File I/O def read_file(path): with open(path) as f: return f.read()
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
a0023a7c
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
4c971249
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
0bfb239f
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
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
31860949
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
77b09404
def count_chars(text): return {c: text.count(c) for c in set(text)}
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
28c63d42
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
6bc97cb9
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
dfbe6610
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Base class cơ bản. **kwargs để flexible initialization.
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" ]
8c16608d
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
13c0e5b5
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
3fcb3f7f
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
19079c00
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]