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
80c2c77d
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Extract emails từ text dùng regex pattern.
File operations là fundamentals trong programming.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
994c1abd
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Extract emails từ text dùng regex pattern.
File operations là fundamentals trong programming.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
76bf2091
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Extract emails từ text dùng regex pattern.
File operations là fundamentals trong programming.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
0d9dae42
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Extract emails từ text dùng regex pattern.
File operations là fundamentals trong programming.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
a4d999d9
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
b7c2afb2
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
895c2258
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
0977ef82
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.
File operations là fundamentals trong programming.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
ea20c990
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
c6ba7c3a
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
94415bab
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
881eedd0
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.
File operations là fundamentals trong programming.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
eafc26c1
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
51a9ae72
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
c10886b0
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.
File operations là fundamentals trong programming.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
3a319fce
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
c5ca762d
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
775a458d
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
60509daa
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
299a1345
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
ea002663
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
File operations là fundamentals trong programming.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
b5df1702
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
File operations là fundamentals trong programming.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
ef996930
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
File operations là fundamentals trong programming.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
49bccf42
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
File operations là fundamentals trong programming.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
eacbf4f2
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
Save data thành JSON file.
File operations là fundamentals trong programming.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
cba4baef
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
File operations là fundamentals trong programming.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
35ab9e55
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
File operations là fundamentals trong programming.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
fe6044f8
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
File operations là fundamentals trong programming.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
761b10b7
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
File operations là fundamentals trong programming.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6058d7f2
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
File operations là fundamentals trong programming.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
c4c0948c
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
File operations là fundamentals trong programming.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
3040c395
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Save data thành JSON file.
File operations là fundamentals trong programming.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ee90296a
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
File operations là fundamentals trong programming.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
32c5c78c
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Save data thành JSON file.
File operations là fundamentals trong programming.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7cc2a3ca
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
File operations là fundamentals trong programming.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
bbc01e54
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
File operations là fundamentals trong programming.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
0a879f46
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
File operations là fundamentals trong programming.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
0b7c959f
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
File operations là fundamentals trong programming.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
c740d85f
# File I/O def read_file(path): with open(path) as f: return f.read()
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d9282c18
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
3d2a555f
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
53d378bc
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
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
b5bff626
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
dbe24191
def count_chars(text): return {c: text.count(c) for c in set(text)}
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
9116d7c2
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5527479a
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
90bbb307
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
29d45ff6
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
631e4de5
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
510fd557
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
6376013c
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
e90a8c3b
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
3b5d3b77
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
cd442687
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
45b52011
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Hàm này đọc nội dung của file và trả về dưới dạng string.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
15d1ea04
# File I/O def read_file(path): with open(path) as f: return f.read()
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
782b1457
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
de088fe2
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
7325e2b9
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
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
5f28eb08
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
1dd293ef
def count_chars(text): return {c: text.count(c) for c in set(text)}
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
0a4773c5
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
63a719d5
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
a04b07bc
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
31d3956b
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
ce4d0ee4
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Ghi nội dung vào file. Context manager tự động đóng file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
f06a78c5
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
2189bf88
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
deb70d10
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
058e1f10
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
6dc6344e
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
69cb1e7b
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
489a4c3c
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
79da08de
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
c2ba61bd
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
af0f4443
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
0047db0c
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
aa963f92
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
ddbebc5d
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
b4a75528
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
0e8ab65a
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
734507b2
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
152e56ed
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
72a99ff0
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
92ea4a16
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
ad27149b
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
a534c08f
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e7e2af74
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
83c3471d
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
feb7db64
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
2d611ad2
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
ad87b91e
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
e00bbe9c
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
11078203
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
05e8418d
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
c8f290b5
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
c6186a32
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
fadabbe2
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
c4b22e0d
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
6638c7b1
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]