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
31fa5100
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
0766e3de
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
fbb83534
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e6bfc3cb
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
4977c915
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
a54e36d3
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Ghi nội dung vào file. Context manager tự động đóng file.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
47a632a6
# File I/O def read_file(path): with open(path) as f: return f.read()
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
ee78dff5
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
507a711e
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
2adeff21
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
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
4780f2e3
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
ade39675
def count_chars(text): return {c: text.count(c) for c in set(text)}
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
9e6ddc05
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
91b5b2d4
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
b2465746
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
6df6c6fc
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
b44c5d15
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
561e2ea9
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
be0d1ad7
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
27c51ae9
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
a40402d3
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
88f10279
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
cf1020b1
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Flatten thường dùng trước khi process lists.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b9735086
# File I/O def read_file(path): with open(path) as f: return f.read()
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d2f3cb69
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
fade822c
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
802c46a1
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
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
8ea1f135
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
70c358a1
def count_chars(text): return {c: text.count(c) for c in set(text)}
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
6a67b46f
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
c0733a7c
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
217e9c0d
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
9193b220
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
a840f7a6
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
1b91cb96
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
ab7eae14
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7d0bf00c
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6298f081
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ab1564e2
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
de2d0979
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Flatten thường dùng trước khi process lists.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
73761fe6
# File I/O def read_file(path): with open(path) as f: return f.read()
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
aede204d
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
94402d72
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
51f678df
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
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
a759e1e4
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
876b97d2
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
bfecb0e9
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3268dcb0
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
1967b535
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
39aa91f6
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7b6f180b
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d4cec181
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
3f413336
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
f4cad9f3
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
d2840b9c
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
42576b3f
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b789500c
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Đảo ngược thứ tự các từ trong text.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
6aa440bf
# File I/O def read_file(path): with open(path) as f: return f.read()
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
47ab4e30
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
aef74c1e
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
cc8800ba
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
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
5097c88f
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
f7b4cd45
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
0e65324f
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
baf27c15
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
fb73fb5b
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
cc163e33
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0bf9df5c
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Đếm tần suất xuất hiện của mỗi ký tự.
Flatten thường dùng trước khi process lists.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]