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
b63414f9
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Fetch data từ API endpoint. Trả về JSON.
Grouping là common operation trong data analysis.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
2d53dbf1
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fetch data từ API endpoint. Trả về JSON.
Grouping là common operation trong data analysis.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
cf964c8b
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fetch data từ API endpoint. Trả về JSON.
Grouping là common operation trong data analysis.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
7f5159f5
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fetch data từ API endpoint. Trả về JSON.
Grouping là common operation trong data analysis.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
efa7af35
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fetch data từ API endpoint. Trả về JSON.
Grouping là common operation trong data analysis.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4e6f3351
# File I/O def read_file(path): with open(path) as f: return f.read()
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
98d2e307
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d412e0b5
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
7ac54275
def group_by_key(items, key): result = {} for item in items: k = item.get(key) if k not in result: result[k] = [] result[k].append(item) return result
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
9d4350b6
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b87b7468
def count_chars(text): return {c: text.count(c) for c in set(text)}
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
11671df6
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5251fc82
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
ba856493
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
079a0eab
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
1d25f28d
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
5e22e888
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
d27da9e1
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
55fb67b3
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
79886797
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
f9539914
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
02c3426d
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Extract emails từ text dùng regex pattern.
Grouping là common operation trong data analysis.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
bbb00c57
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
2ff9120e
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
3604639c
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
03e60099
def group_by_key(items, key): result = {} for item in items: k = item.get(key) if k not in result: result[k] = [] result[k].append(item) return result
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
948a4ec0
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
bd2fbf4c
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
a44b3268
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
0b9ebdf2
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
5c9f3dc8
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
a66f619e
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
6474703b
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.
Grouping là common operation trong data analysis.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
56a21ed4
# 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.
Grouping là common operation trong data analysis.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
f01d78ef
# 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.
Grouping là common operation trong data analysis.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
446d38f1
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
6525dcb9
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
a12e9d61
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
7cf2d4f1
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Grouping là common operation trong data analysis.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
e8fdde2c
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
67bdb7e2
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
9bfd0022
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
835a9732
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.
Grouping là common operation trong data analysis.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
6e965e8d
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
43344f1c
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
1dd1a0a2
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
2f1fa27a
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
7d903aa7
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
7e60ad78
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
51394118
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.
Grouping là common operation trong data analysis.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
b68520de
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
880e02ad
# 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.
Grouping là common operation trong data analysis.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7754d061
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
4f889f7f
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9b3e6502
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
9d14643b
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
Grouping là common operation trong data analysis.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
bcfc73ec
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
9be3a9b5
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.
String manipulation dùng .split() và slicing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
669f07a0
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
4d45fdfc
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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
08c512bd
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
d8847904
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.
String manipulation dùng .split() và slicing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
e046b346
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
8667fb7b
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.
String manipulation dùng .split() và slicing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
c101a2d8
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
d17771d0
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
cd7fc1d8
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.
String manipulation dùng .split() và slicing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
940de8b8
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
2422735f
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
2c8ac8e3
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
9030f7b0
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
365ceaac
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
22a3fda0
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.
String manipulation dùng .split() và slicing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
ff6869b7
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
6cb922f9
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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
5d8b74ea
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
5ab0319a
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.
String manipulation dùng .split() và slicing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
367c8646
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Ghi nội dung vào file. Context manager tự động đóng file.
String manipulation dùng .split() và slicing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
80133bba
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.
String manipulation dùng .split() và slicing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
46916568
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
474564fe
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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
e9dd95a6
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
4ab5c0e6
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
47fdbc78
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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
65f71533
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
a99301e7
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
2b5761f0
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
ad5b8973
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
070469a2
# 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.
String manipulation dùng .split() và slicing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
8c2ec6a0
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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
7df6649c
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
1f2c2c70
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.
String manipulation dùng .split() và slicing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
8c0e6795
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
8915e328
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.
String manipulation dùng .split() và slicing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
160fc5a2
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
String manipulation dùng .split() và slicing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
d453a830
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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
8fe278bd
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
2e6b1152
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.
String manipulation dùng .split() và slicing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
781f0ab5
# 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.
String manipulation dùng .split() và slicing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
ec94b74c
# 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.
String manipulation dùng .split() và slicing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]