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
94a091ec
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
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
c0cca6ba
# 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
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
9166ad8b
# 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
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
fd45e382
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
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
8e740d40
# 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
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
452b07e6
# 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
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
727d8f2f
# 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
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e1487263
# 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
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e1ae9d20
# 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
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
fa801b09
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
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4912aa7f
# 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
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
a269d310
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
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
48f446f1
# 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
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
1037d8aa
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
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
6f15b9b7
# 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
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
c939fe0e
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
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
bc93df57
# 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
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
b50b948d
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
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
fcdd27a1
# 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
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
179b41dc
# 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
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
a4372e50
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
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
87e29d05
# 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
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
de8cc175
# 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
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
66e67f15
# 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
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
7d3e46d4
# 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
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
018c33b2
# 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
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
bc1e7f06
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
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
36a0ed7a
# 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
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
9a432ec6
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
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
726b2639
# 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
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
78d9b8ea
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
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
115254ec
# 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
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
8b58631d
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
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
005b3489
# 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
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
e4634cdb
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
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
bbd62fea
# 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
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
d569411e
# 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
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
e0282731
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
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
121deb3a
# 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
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
ef3613f5
# 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
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
f217d8fd
# 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
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
144bc406
# 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
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
24e31bb2
# 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
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
2c21e028
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
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
9c262506
# 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
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
e3e1feec
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
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d53fdf90
# 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
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
641c0ac7
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
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
95d965c2
# 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
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
673abccc
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
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
9b2460a2
# 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
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
8f4213e5
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
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
7bbd52d8
# 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
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
35ac4203
# 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
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
fb21209c
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
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
49e58660
# 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
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
4a85d993
# 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
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8056c60b
# 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
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
ea2ac354
# 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
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
0e182c0b
# 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
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
4ed81c69
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
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
dcbbd6ab
# 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
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
8637c10b
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
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" ]
c5ac8678
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
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" ]
73b7fc21
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.
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" ]
f63a693b
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
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" ]
6d3aa4d6
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
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" ]
e4f39fe6
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
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" ]
ac8697f5
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
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" ]
38374bff
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
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" ]
157e3d2d
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
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" ]
1052b612
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.
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" ]
0bbcabaf
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
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" ]
d583cf4d
# 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.
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" ]
49d72a35
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
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" ]
954792b4
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
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" ]
4b83715b
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
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" ]
a21afa3d
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
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" ]
cbfba2ba
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d516c140
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.
Thường dùng trong data preprocessing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
54b686ae
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
260ea128
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.
Thường dùng trong data preprocessing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
e38d5321
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a8a37668
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
127b08a5
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
f084651b
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.
Thường dùng trong data preprocessing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
2d14a287
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
da2740b7
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0812ccf6
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.
Thường dùng trong data preprocessing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
7f6437b6
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
edba6d7c
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
9195ed77
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
d7413bc2
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
029eca5d
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
7e92be6b
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.
Thường dùng trong data preprocessing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
c5c47ec9
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
250bfbb9
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.
Thường dùng trong data preprocessing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
96536a5e
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
5bebbd45
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
5ea437e4
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
Thường dùng trong data preprocessing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]