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
32d3f6fc
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
01dad289
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
d141c715
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
6d3e4a11
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
b798e89b
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
530d76ec
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
7f0cb3bc
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
52604167
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
36b0bf1a
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0442bb1d
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
2d650299
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
162ea16f
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
Prime checking dùng trong many algorithms.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
0c16a184
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
20ce2a4d
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5a863856
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
3078376f
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
863fab47
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
519a7411
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
baaadc16
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
f49c2c33
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1cf0abdb
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
53ab06cd
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
0b50beeb
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
f122ddae
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
c53d3c17
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
677db7e6
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
fed483c9
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
efe60cc5
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
6cd8d2c0
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Prime checking dùng trong many algorithms.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
502f51c2
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
dcc8fae8
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
c2bc629a
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
9d6ab703
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
7a43946e
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
f80bdccf
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
0e8de114
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
e8584c5a
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7ede12af
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
70f02fef
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
b0f88336
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b92df4c5
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
73c1859e
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3b641286
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
5a73f0af
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
fe483452
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
447f4a9f
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a710726f
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
63a7f239
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
78409f66
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
125c7c17
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
549f1936
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
97d00e7b
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
0741f693
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
70793305
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
b4f644f9
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
10ca74b5
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e9ad7ed2
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
ef64bbd7
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
e4651f79
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
6a697913
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
Prime checking dùng trong many algorithms.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
df0677ff
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
efbefe84
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.
Prime checking dùng trong many algorithms.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
0512b4dc
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
Prime checking dùng trong many algorithms.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
e3041c0b
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
Prime checking dùng trong many algorithms.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
713309e0
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
fa137601
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
fa9f45b5
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
1cceee72
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0ee2b3d1
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
00037bed
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
06e158f8
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
6ff42672
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đảo ngược thứ tự các từ trong text.
Prime checking dùng trong many algorithms.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
038bc533
# 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.
Prime checking dùng trong many algorithms.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
0bda95e9
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
66258967
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
9d4b9994
# 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ự.
Prime checking dùng trong many algorithms.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
1e1b88f6
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ự.
Prime checking dùng trong many algorithms.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
656208b2
# 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ự.
Prime checking dùng trong many algorithms.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
fc3192eb
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ự.
Prime checking dùng trong many algorithms.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
74dc895b
# 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ự.
Prime checking dùng trong many algorithms.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
3028a177
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ự.
Prime checking dùng trong many algorithms.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
bf177246
# 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ự.
Prime checking dùng trong many algorithms.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
1c96d55f
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ự.
Prime checking dùng trong many algorithms.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
f91ae7d4
# 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ự.
Prime checking dùng trong many algorithms.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
f2207195
# 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ự.
Prime checking dùng trong many algorithms.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
4c69eb3a
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ự.
Prime checking dùng trong many algorithms.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
61e1cf9b
# 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ự.
Prime checking dùng trong many algorithms.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
dc2beaf0
# 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ự.
Prime checking dùng trong many algorithms.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
583964f4
# 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ự.
Prime checking dùng trong many algorithms.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
4f806612
# 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ự.
Prime checking dùng trong many algorithms.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
88a0f89d
# 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ự.
Prime checking dùng trong many algorithms.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
f7122faf
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ự.
Prime checking dùng trong many algorithms.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
dc69c936
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
db088b35
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Làm phẳng list nested thành flat list.
Prime checking dùng trong many algorithms.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
ad51d37b
# 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.
Prime checking dùng trong many algorithms.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
2f00c1d0
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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
1772cf39
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Làm phẳng list nested thành flat list.
Prime checking dùng trong many algorithms.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
cfb43b47
def count_chars(text): return {c: text.count(c) for c in set(text)}
Làm phẳng list nested thành flat list.
Prime checking dùng trong many algorithms.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
a2eac6ff
# 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.
Prime checking dùng trong many algorithms.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
2ac203fe
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.
Prime checking dùng trong many algorithms.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]