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
568689b6
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
e9d86eef
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
ba81ee30
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
8d8f5c7d
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
c43d7ce9
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
45005b41
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
faba65d7
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a81c7206
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6f9e5166
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
a400b112
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
275c383b
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
5901d032
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
fe012f89
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
624fcd34
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
e4f5e2e8
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
54dd02cf
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fibonacci recursive. Chậm nhưng minh họa recursion.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
6d78551a
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fibonacci recursive. Chậm nhưng minh họa recursion.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
0afec13c
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
9de2de33
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
b967a3c1
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
1f11375c
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
be171d3a
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
5c2a6d6e
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
79313eba
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a27ee1fa
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fibonacci recursive. Chậm nhưng minh họa recursion.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
660b36db
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e9eb5280
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
90f89a47
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b13b7edc
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d1401ce6
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
1f3ed890
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
45dcf240
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
16ceaf10
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
0dba17ab
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
d128b215
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
eeb9cefd
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
4ecb9153
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
8967fc6a
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
f79beb10
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ae2a31d7
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
d335c1d7
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
f67aa3b8
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6ecd5042
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
403aa559
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
7dbd425a
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
04397335
# File I/O def read_file(path): with open(path) as f: return f.read()
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
07efb397
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
08d1070c
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
60907052
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
27d292d0
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
aebd2fb4
def count_chars(text): return {c: text.count(c) for c in set(text)}
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
6187d953
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
9a212a24
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
43a43a24
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
38138296
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
10f2a45c
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
6880cef6
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
8a8eabdd
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
6b207e6e
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
259860d8
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
03e539d5
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
007ac3be
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Base class cơ bản. **kwargs để flexible initialization.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
c0afd5cb
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
a4c16ccb
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d9cd514f
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
f4f6421d
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
fe9004b6
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
fb6f1f73
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
29409d63
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
46917a72
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
4c9fe094
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
2f18a5e4
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
b73e9498
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
8336bdcf
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
3296e758
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
798a96e4
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e8b47629
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
6ae5e0e5
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
c32a49d7
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
7a92bdc4
# File I/O def read_file(path): with open(path) as f: return f.read()
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
acbfd971
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
6888618d
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
ff91ef9e
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
378fa7ba
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
30554579
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
f3e71415
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
64327033
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
fcdee1d3
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
dea0099b
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
2ff65c4c
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ee2f1272
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
13dca164
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
57282453
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
1fc1a3f6
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
f0fe4cdc
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
566548e6
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fetch data từ API endpoint. Trả về JSON.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
da9816a1
# File I/O def read_file(path): with open(path) as f: return f.read()
Extract emails từ text dùng regex pattern.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
581f4294
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Extract emails từ text dùng regex pattern.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
6371c067
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Extract emails từ text dùng regex pattern.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
512e14f8
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]