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
1304722e
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
2008d3c2
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
0f5b163e
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
d5830e16
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3e000c83
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
c4122c41
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
12a0163c
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
a1b73fd1
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
c952eacc
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
f88ec2a6
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1aea0bab
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e5c2abe5
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
268fa96a
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
78b71298
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b23a695a
# File I/O def read_file(path): with open(path) as f: return f.read()
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
7d53418d
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
219b3869
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
03ae8b48
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
c4e3fcf7
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
490341e3
def count_chars(text): return {c: text.count(c) for c in set(text)}
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
80021a6e
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
b55ec518
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
670ed7fe
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
da681a66
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
493c0f4c
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ce09808a
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
9694889e
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
dbd0cce2
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
4ca6554c
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
f9f3d49a
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
84fafea9
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Base class cơ bản. **kwargs để flexible initialization.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
7352a580
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
bb35fbde
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
065a1a5e
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
fe9b3ff4
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
4e264083
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
04339f5a
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
da664f6f
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3ece3808
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
a46088ba
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
ce1da7dc
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
daf17c04
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
91dd8bc2
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
b772e633
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
50a9a060
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
17106db1
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
38afd2ee
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
6e9bb614
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
d9adbf04
# File I/O def read_file(path): with open(path) as f: return f.read()
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
9f5b879d
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0526bb70
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
a9d5e844
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
49828f03
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a32a4b35
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
8b615851
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
37d13be8
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
73229eb6
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
1ff9027b
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
fce75fa1
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
6d65ad90
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
569a8194
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
564c4a57
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
7d0e884e
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
dc0f32cc
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
850a4769
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fetch data từ API endpoint. Trả về JSON.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
12e39d54
# File I/O def read_file(path): with open(path) as f: return f.read()
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
5c5266a0
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
c891f3a0
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
567f54c0
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
dce08ee5
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
6c1a66e9
def count_chars(text): return {c: text.count(c) for c in set(text)}
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
75b2495c
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
05790711
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
d3728ccd
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
bd12c8b5
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
332233c7
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
4667070f
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
534a1a35
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
aaf1b71d
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
0a3de279
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
bf86d52a
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
a641f418
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Extract emails từ text dùng regex pattern.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
f4d2302a
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
1e60dc0e
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
8cd09216
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
b42fe03b
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
d0a61eae
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
c73c5921
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
e00018ef
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
49b01426
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
34d87821
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
478c063e
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
e3ec5f9b
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
b9c83b59
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
b172f2dc
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
6fa50fe9
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
fbfcc241
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9f6754da
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
16d7cbcd
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
039087d2
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]