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
6dff18e6
# 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
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
3ebc934f
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
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
05348ab7
# 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
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
833bbcda
# 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
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
9f699118
# 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
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e19c9e86
# 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
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
b2ee388c
# 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
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
adaa8481
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
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
c8c2cd34
# 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
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
80f16a6a
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
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
3b21b70a
# 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
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
2943b995
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
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
eb3dd7a5
# 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
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
5e807d47
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
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
1a4e5cb1
# 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
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
d2f411ff
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
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
457e8ccf
# 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
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
e0f953a3
# 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
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
a064b4a1
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
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
58c62c26
# 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
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
c9337e9b
# 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
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8ef7df32
# 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
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
25b1f0f5
# 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
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
a339f63e
# 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
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
7dc0c289
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
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
2a3da198
# 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
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
ac5765fc
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
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
6646ae41
# 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
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
4edd51ee
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
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
f2a28232
# 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
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
512ed67b
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
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
7fac29ab
# 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
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
d1f11a87
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
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
3c9ac480
# 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
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
49708ebb
# 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
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
ee255877
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
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
1e08930e
# 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
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
31d8f6fd
# 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
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
816f8eaa
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e9552804
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9a7b9935
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
1b6420f3
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
86358183
# File I/O def read_file(path): with open(path) as f: return f.read()
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
d46e9521
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
e6aa0550
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
138fef3a
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
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
515bfdc5
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b6dd091e
def count_chars(text): return {c: text.count(c) for c in set(text)}
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
576f0f64
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
9b51cf3c
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
08b4c0e2
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
97b8cfa2
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
393134dc
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
f69b04bd
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
8cdc74e6
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1b67111f
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
5a737ac5
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
198f5c5d
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
8968c2bc
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Decorator log_calls ghi lại mỗi lần function được gọ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" ]
fc4849b9
# File I/O def read_file(path): with open(path) as f: return f.read()
Fetch data từ API endpoint. Trả về JSON.
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" ]
8c841183
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fetch data từ API endpoint. Trả về JSON.
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" ]
1a3b2af8
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
c155188c
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
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
560ae805
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
e4729658
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
45245e4e
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5bdd415a
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
b2d404b5
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fetch data từ API endpoint. Trả về JSON.
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" ]
332d5767
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
77b6c7c3
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
e85ff89e
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
f7d2759f
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
3ce3552b
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
f333c541
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
8783b8a1
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
054935bc
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
81c2b71f
# File I/O def read_file(path): with open(path) as f: return f.read()
Extract emails từ text dùng regex pattern.
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" ]
813e0556
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Extract emails từ text dùng regex pattern.
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" ]
7d481c71
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
058c7a18
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
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
4d695409
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
4e5e1153
def count_chars(text): return {c: text.count(c) for c in set(text)}
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
3d0a5e89
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
29564399
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6dce0a36
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Extract emails từ text dùng regex pattern.
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" ]
bc59659f
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
4256e24d
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
7d50994f
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
b8d3f0f0
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
48e3d8d1
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
62db3466
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
53641c0c
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
0f72cc6e
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4f1bbdb4
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
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" ]
0f16c6a7
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
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" ]
6a987cb5
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
6e2042de
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
fa5de509
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
512cd315
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
31fb2b82
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]