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
5e0d07ae
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.
JSON là standard format cho data interchange.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
26d93010
# 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.
JSON là standard format cho data interchange.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
09daf953
# 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.
JSON là standard format cho data interchange.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
1a985110
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
JSON là standard format cho data interchange.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
5e9ea4c9
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
JSON là standard format cho data interchange.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
4b89b8da
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
JSON là standard format cho data interchange.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
9cd028bc
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
JSON là standard format cho data interchange.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
95b6baa4
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
JSON là standard format cho data interchange.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
6bdadbee
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
JSON là standard format cho data interchange.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0c4809cf
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
JSON là standard format cho data interchange.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
9fc87906
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.
JSON là standard format cho data interchange.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
ba7bc8f5
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
JSON là standard format cho data interchange.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
c9924026
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
JSON là standard format cho data interchange.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
b61aad2e
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
JSON là standard format cho data interchange.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
03fc4a45
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
JSON là standard format cho data interchange.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
f00a5b98
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
JSON là standard format cho data interchange.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
516fb333
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
JSON là standard format cho data interchange.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
0b4aec09
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.
JSON là standard format cho data interchange.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
f073c72e
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
JSON là standard format cho data interchange.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
b34d6df7
# 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.
JSON là standard format cho data interchange.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
0caf70b7
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
JSON là standard format cho data interchange.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
306b195c
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
JSON là standard format cho data interchange.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9cbc131b
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
JSON là standard format cho data interchange.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
2671820c
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
JSON là standard format cho data interchange.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
11d0dcb2
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
ef12cff0
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.
File operations là fundamentals trong programming.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
097211ff
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
16832822
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.
File operations là fundamentals trong programming.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
da5fa9f8
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
61e5c0ac
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.
File operations là fundamentals trong programming.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
01dfcc9d
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
433a26e4
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.
File operations là fundamentals trong programming.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
9b259e87
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
7a391676
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
f500f808
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.
File operations là fundamentals trong programming.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
11ac011c
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
1d33a2ea
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
6ebae505
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
948c8b72
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
501cf9b5
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
c2dfccc0
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.
File operations là fundamentals trong programming.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
03011768
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
5ab588a9
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.
File operations là fundamentals trong programming.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d69b49af
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
ef1a0f44
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.
File operations là fundamentals trong programming.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
b943d104
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
File operations là fundamentals trong programming.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b4ec880c
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.
File operations là fundamentals trong programming.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
ae37f017
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
d0420dc7
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.
File operations là fundamentals trong programming.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
d9a10a31
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
b5440bf7
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
774049a0
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.
File operations là fundamentals trong programming.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
425c4a81
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
41a53279
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
3612b562
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
757e4fdd
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9a694d8e
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
fc3e922d
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.
File operations là fundamentals trong programming.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
45bda472
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
1006da47
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.
File operations là fundamentals trong programming.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
11b52398
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
ffbc0c5c
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.
File operations là fundamentals trong programming.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
8c89cdd3
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
File operations là fundamentals trong programming.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b9875d66
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.
File operations là fundamentals trong programming.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
e3c99745
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
3b292865
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.
File operations là fundamentals trong programming.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6b6358cf
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
9fc778d7
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
8f46fdff
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.
File operations là fundamentals trong programming.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d96df86a
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
dd8ef02d
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8c216c2d
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
c61d7315
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
892053aa
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
1705b97a
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.
File operations là fundamentals trong programming.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
92b9f134
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
7684e105
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.
File operations là fundamentals trong programming.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
bde4e72a
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
55db62d0
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.
File operations là fundamentals trong programming.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
8dfbb060
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
1009fc5d
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.
File operations là fundamentals trong programming.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
6897c4ee
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
7ef2d8aa
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.
File operations là fundamentals trong programming.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6e29f50c
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
bb6b7bac
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7ad63465
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.
File operations là fundamentals trong programming.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
754fa6cc
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
138b0050
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
c88b4d54
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
a9dc6fdd
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ec71d29f
# 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.
File operations là fundamentals trong programming.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
abd69104
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.
File operations là fundamentals trong programming.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
97811285
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
b6f2b761
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
File operations là fundamentals trong programming.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
9f4214e1
# 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.
File operations là fundamentals trong programming.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
697f8f40
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.
File operations là fundamentals trong programming.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
45e90720
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
File operations là fundamentals trong programming.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a64bc9d6
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
File operations là fundamentals trong programming.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
b2c8e17f
# 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.
File operations là fundamentals trong programming.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
18e849e9
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.
File operations là fundamentals trong programming.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]