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
a096e042
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
fbf04cfe
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
b6b9c245
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
0e328739
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
fb4e695e
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
687465e9
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
05119e06
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
c4cfe1e1
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
61966b56
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
b8c627c1
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
bacb1211
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b98e7c19
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
ae539ae1
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
52f1c51e
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
f568027e
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
facd66ba
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
362c0d61
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fibonacci recursive. Chậm nhưng minh họa recursion.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
7904ecc1
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fibonacci recursive. Chậm nhưng minh họa recursion.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
cbc858fe
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
26e0ea4b
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
9b004b90
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
169dc397
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
31b0b2ce
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
298d339a
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
441ca3f4
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
cbc64ce2
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fibonacci recursive. Chậm nhưng minh họa recursion.
Flatten thường dùng trước khi process lists.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
28875837
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9ee3fd43
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
6e86151c
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
a3dc99d9
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
17b5fa3a
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
952802d2
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
4adcd044
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
5de96076
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
fada4d93
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
5f02fb60
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
a930052f
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
1b3c6670
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
a90ae51b
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
56e63b4f
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d7fdb06f
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
ac2ddecf
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
067a1474
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
c6edc644
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
6bd42200
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b25fc59b
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
967809ce
# File I/O def read_file(path): with open(path) as f: return f.read()
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
f611651e
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d1c42a98
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
3a97f43c
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
b6afa6b4
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
52a542f9
def count_chars(text): return {c: text.count(c) for c in set(text)}
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
6bb722fc
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
a527e2f9
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
a9cf1a1d
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
50f69329
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0240a908
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
6559964c
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
93146bdc
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
574b1b25
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
99dbc3c1
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
7cabf312
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
af1cdbfb
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Base class cơ bản. **kwargs để flexible initialization.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
585f447f
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
ffee1861
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
762edd3e
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
8953e307
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
b180ec55
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
5d32f9a3
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
e30d4da9
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
f6ff1b02
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6b4205c9
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
5dc7267a
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
d340fcd6
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
f940cedb
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
0ab87b55
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
4c7152e8
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
2317ba22
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
44e923a0
# 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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
df958182
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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
57f62d0a
# File I/O def read_file(path): with open(path) as f: return f.read()
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
9d15ccde
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
1f7ab670
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
c21257dc
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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
8ab198ef
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
4d8f0953
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
4c2724d1
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
7c518ec1
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
98adfa6c
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
1ffd4445
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7d514cb5
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.
Flatten thường dùng trước khi process lists.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
47dda61e
# 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.
Flatten thường dùng trước khi process lists.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
36511a3c
# 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.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8c42341a
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6708a010
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
f1add09a
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
89f137a9
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fetch data từ API endpoint. Trả về JSON.
Flatten thường dùng trước khi process lists.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
11bbb938
# File I/O def read_file(path): with open(path) as f: return f.read()
Extract emails từ text dùng regex pattern.
Flatten thường dùng trước khi process lists.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
7832d77b
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Extract emails từ text dùng regex pattern.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
79c2d6ed
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Extract emails từ text dùng regex pattern.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]