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
458b7467
# 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ự.
OOP base class cho extensibility.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
51c7c884
# 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ự.
OOP base class cho extensibility.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
c6dbe7e1
# 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ự.
OOP base class cho extensibility.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
ad01027b
# 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ự.
OOP base class cho extensibility.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
a0414fa8
# 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ự.
OOP base class cho extensibility.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
7d7e98d0
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ự.
OOP base class cho extensibility.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
1b9f6955
# 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.
OOP base class cho extensibility.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
4fbb2432
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
64ec3ea7
# 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.
OOP base class cho extensibility.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
bb23aad2
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.
OOP base class cho extensibility.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
26eb7d25
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
3d2d6f4a
def count_chars(text): return {c: text.count(c) for c in set(text)}
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
bdefd1e4
# 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.
OOP base class cho extensibility.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
fce9c0a0
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.
OOP base class cho extensibility.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
e8a347de
# 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.
OOP base class cho extensibility.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
c02f4557
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
65ff411d
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
c228f289
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
6ab8f20e
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
575e86b6
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
703a9a45
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
cf3404f3
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
1d92c3ed
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Làm phẳng list nested thành flat list.
OOP base class cho extensibility.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4559be6f
# File I/O def read_file(path): with open(path) as f: return f.read()
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
dc792783
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
1a521acb
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
4097935b
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
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
fb6d10cc
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
f94559a2
def count_chars(text): return {c: text.count(c) for c in set(text)}
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
4b69df58
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
a3a82be7
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
3db0da97
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
dec25798
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0c86a6b4
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
e5fcc94a
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
3906667c
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
a22a39ec
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
3707057e
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ccc33e6e
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
5e5cd093
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Gộp nhiều dictionaries thành một.
OOP base class cho extensibility.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
2830e488
# File I/O def read_file(path): with open(path) as f: return f.read()
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
c94fac51
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
810f2efd
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
b9d03f77
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
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
384bcaa1
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
15fb8b46
def count_chars(text): return {c: text.count(c) for c in set(text)}
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
1955bdb2
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
a476f497
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
385b6ba1
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
68ae4e77
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
4de9bb4f
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
c3797afa
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
77345ebf
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
56a19713
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
08bdd7f0
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
026fe7b1
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
f8f8f512
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Chuyển đổi string thành int, trả về default nếu lỗi.
OOP base class cho extensibility.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
76976f3a
# File I/O def read_file(path): with open(path) as f: return f.read()
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
8fea30bf
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
93766d79
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
f4a6df56
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
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
403d2088
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a1e36dfa
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
f7567e54
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
bdbd6e62
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
2276f9d2
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
f09c86bd
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
ef0a5cd9
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d884b5d3
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
a2d0821d
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
bccfd93e
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
9ffe40b3
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
52eb5a07
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
c4ce7334
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fibonacci recursive. Chậm nhưng minh họa recursion.
OOP base class cho extensibility.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
9ce4a186
# File I/O def read_file(path): with open(path) as f: return f.read()
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
4b7e05c1
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
bd2a2938
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
9ccab462
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
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
39e62484
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
69adb524
def count_chars(text): return {c: text.count(c) for c in set(text)}
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
da519528
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
8c4b015a
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
aeef67c8
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
e1758c2d
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
9463fe5c
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
3edfa812
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
4be75343
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
68c5de18
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
83e313c2
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e6cf5327
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
c4f0363d
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Kiểm tra số nguyên tố. Dùng all() để check tất cả divisors.
OOP base class cho extensibility.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
d915400d
# File I/O def read_file(path): with open(path) as f: return f.read()
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
b8bcbe2a
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
76dd1eb2
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
778cd1e6
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
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
a8507d49
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
00bf365f
def count_chars(text): return {c: text.count(c) for c in set(text)}
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
05f69c44
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
21a98ca5
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
740cd34b
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Base class cơ bản. **kwargs để flexible initialization.
OOP base class cho extensibility.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]