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
8003e799
# 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.
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" ]
96645ff3
# 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.
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" ]
30ce9390
# 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.
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" ]
8ff95f01
# 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.
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" ]
863a0541
# 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.
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" ]
36bbb7d0
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.
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" ]
29cb265d
# 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.
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" ]
397e9eca
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.
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" ]
82fc5e37
# 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.
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" ]
285a0c5f
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.
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" ]
70da2374
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng 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" ]
21606b0e
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.
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" ]
f8f51208
# 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.
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" ]
333d0c3e
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.
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" ]
a500e0d4
# 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.
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" ]
631eb7be
# 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.
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" ]
6400b368
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.
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" ]
ff146a9a
# 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.
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" ]
0a48695d
# 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.
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" ]
69a54956
# 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.
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" ]
33d908c5
# 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.
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" ]
51d666c9
# 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.
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" ]
c36756ec
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.
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" ]
44976692
# 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.
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" ]
09bfc818
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.
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" ]
f247d336
# 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.
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" ]
9f0ff0f1
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.
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" ]
ac8a8ce6
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
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" ]
921d9445
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.
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" ]
6ddd0c61
# 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.
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" ]
3f9b916b
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.
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" ]
4b8fa18d
# 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.
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" ]
54e875dd
# 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.
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" ]
0085ee8d
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.
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" ]
bbd128a6
# 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.
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" ]
a0e4fa5c
# 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.
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" ]
00d3b5d9
# 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.
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" ]
ecfc684f
# 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.
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" ]
80d9e1a4
# 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.
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" ]
57a68c80
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.
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" ]
a9bdfd8c
# 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.
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" ]
53c6f5cb
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.
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" ]
54dd75cc
# 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.
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" ]
b300bf6f
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.
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" ]
ec993599
# 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.
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" ]
e74f01b7
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.
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" ]
546c07bd
# 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.
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" ]
f4975f90
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.
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" ]
3dac4cff
# 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.
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" ]
297cbec1
# 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.
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" ]
b40006fb
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.
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" ]
6a62a95f
# 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.
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" ]
3b4986f8
# 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.
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" ]
39061ff2
# 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.
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" ]
21be8a06
# 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.
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" ]
50ff9dcb
# 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.
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" ]
bd55b814
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.
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" ]
208eb820
# 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.
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" ]
6e9f87b6
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
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" ]
d73f98f5
# 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.
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" ]
7804dd70
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.
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" ]
40e6954d
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
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" ]
664c5012
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
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" ]
7adb82b0
# 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.
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" ]
4765f58b
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.
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" ]
7ff1dea6
# 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.
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" ]
a432cebe
# 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.
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" ]
c8b508d9
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.
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" ]
5c7c9d08
# 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.
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" ]
fe886924
# 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.
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" ]
01c5cb0a
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đảo ngược thứ tự các từ trong text.
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" ]
1d629fab
# 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.
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" ]
b006400d
# 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.
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" ]
187075be
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.
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" ]
17c2cc04
# 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ự.
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" ]
f370a1f3
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ự.
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" ]
27b132df
# 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ự.
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" ]
413612e5
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ự.
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" ]
2156130c
# 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ự.
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" ]
5f653c98
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ự.
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" ]
d3a9f99c
# 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ự.
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" ]
a73a9ab4
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ự.
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" ]
1b67e6e2
# 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ự.
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" ]
022d6d8b
# 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ự.
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" ]
5d687e26
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ự.
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" ]
ab45a2ae
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Đếm tần suất xuất hiện của mỗi ký tự.
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" ]
984f773a
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Đếm tần suất xuất hiện của mỗi ký tự.
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" ]
21458ef6
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đếm tần suất xuất hiện của mỗi ký tự.
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" ]
6c9fd8ab
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Đếm tần suất xuất hiện của mỗi ký tự.
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" ]
6abd14c5
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Đếm tần suất xuất hiện của mỗi ký tự.
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" ]
a01f2ab3
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Đếm tần suất xuất hiện của mỗi ký tự.
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" ]
9fb7c6df
# File I/O def read_file(path): with open(path) as f: return f.read()
Làm phẳng list nested thành flat list.
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" ]
e1d48038
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Làm phẳng list nested thành flat list.
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" ]
b52af939
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Làm phẳng list nested thành flat list.
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" ]
9f45f4c4
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
Làm phẳng list nested thành flat list.
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" ]
8c4920a7
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Làm phẳng list nested thành flat list.
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" ]
5239c0b7
def count_chars(text): return {c: text.count(c) for c in set(text)}
Làm phẳng list nested thành flat list.
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" ]
075c6b92
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Làm phẳng list nested thành flat list.
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" ]
a50e4c62
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Làm phẳng list nested thành flat list.
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" ]
fad1c99f
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Làm phẳng list nested thành flat list.
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" ]