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
20466d5f
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e15aa579
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
60b3e8d7
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
d3665d16
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Base class cơ bản. **kwargs để flexible initialization.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
141247b9
# File I/O def read_file(path): with open(path) as f: return f.read()
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
8eb4bf2e
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
3268e54a
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
e3f06020
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
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
c3259d09
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
fa7ecc20
def count_chars(text): return {c: text.count(c) for c in set(text)}
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
0e99e6ed
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
339d1af4
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
1caa8ca2
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
948ea48f
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
82f03c11
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
06924909
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
70a48b6f
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
4df95695
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
cf6edcb1
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
020da5b4
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
c5fe1a00
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Decorator log_calls ghi lại mỗi lần function được gọi.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
6fa84c4d
# File I/O def read_file(path): with open(path) as f: return f.read()
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
6a17c2bf
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
417d820e
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
7ac562d1
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
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
75117659
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
4e82d475
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
a2a4f81a
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
0dc4eaf0
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
2301f32c
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
a1f7bb9d
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
a48b2cb5
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
30909f78
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
dc478630
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
bd7674a6
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
d37850cd
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
614bae6c
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
6f1f8cea
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Fetch data từ API endpoint. Trả về JSON.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
970d7c92
# File I/O def read_file(path): with open(path) as f: return f.read()
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
e708cad4
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
0616707f
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
091be1c2
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
64cac14e
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
3e81e28e
def count_chars(text): return {c: text.count(c) for c in set(text)}
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
11c81f48
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
27467b8e
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
4a6ec4bb
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
92525665
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
5f8d6781
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
08658981
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
0fcada26
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
9d63df6b
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
9c0feb49
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
c8612c24
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
28398106
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Extract emails từ text dùng regex pattern.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
0c49a2da
# File I/O def read_file(path): with open(path) as f: return f.read()
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
aa0e4454
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
6005e62e
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
90885a8a
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
eed05f43
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
67565858
def count_chars(text): return {c: text.count(c) for c in set(text)}
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
00676fbe
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
243bf265
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
ef98b0aa
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
9e4c7c8b
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
22683ce2
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
df3cc849
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
f9a0f51a
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
43578b62
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
babb6701
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
e193c280
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
5248fc7a
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Load JSON từ file. Trả về parsed object.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
67818965
# File I/O def read_file(path): with open(path) as f: return f.read()
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
2d0d49bc
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
e383172a
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
966a8a3a
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
d6d4994d
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
6a8efd69
def count_chars(text): return {c: text.count(c) for c in set(text)}
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
64131c16
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5d3a79d2
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
a05fef3e
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
fa4d675d
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
755c79e9
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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
9b2683c0
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
7e413f6f
# 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.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
10d5826a
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
f2a11b05
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
5e28bfb3
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b4b1c822
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Save data thành JSON file.
Sử dụng khi cần đọc toàn bộ file vào memory.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
e417d6a0
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
a3ee8b88
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
ab4bc907
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
b3b57736
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
c707184a
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
e977ffd1
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
088d4d0d
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
95ae2794
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
06ee4301
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
7f33b0ee
# 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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
767e204c
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.
Ghi nội dung mới vào file, overwrite nếu tồn tại.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]