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
966c319b
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
4659fcbf
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
8439f657
def count_chars(text): return {c: text.count(c) for c in set(text)}
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
24757ba2
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
d880a9a7
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.
Thường dùng trong data preprocessing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
c237dbd7
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
e6907ac7
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
b8c22060
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.
Thường dùng trong data preprocessing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
91e7da73
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
83a55d89
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
0df5aa25
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
40af8f08
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
d7224372
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
ae9e7a2f
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Gộp nhiều dictionaries thành một.
Thường dùng trong data preprocessing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
8cc67d2c
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3d0f2647
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
23315c23
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
9e5ecdfe
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.
Thường dùng trong data preprocessing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
8e727c46
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
fba20827
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.
Thường dùng trong data preprocessing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
4210e8a1
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
91763e67
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
9f9ef453
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
baa56035
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
fa73abb2
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
4e250456
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
56a69f81
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
e016fb11
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
3bb94ee7
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
7d200116
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
b50a04ad
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4c379129
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d8bdeb18
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Fibonacci recursive. Chậm nhưng minh họa recursion.
Thường dùng trong data preprocessing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
5904cec5
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
5490585d
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.
Thường dùng trong data preprocessing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
436dab55
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Fibonacci recursive. Chậm nhưng minh họa recursion.
Thường dùng trong data preprocessing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
4d17a841
def count_chars(text): return {c: text.count(c) for c in set(text)}
Fibonacci recursive. Chậm nhưng minh họa recursion.
Thường dùng trong data preprocessing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
ee75efde
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
996077fe
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.
Thường dùng trong data preprocessing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
0a55043c
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
4fb008b5
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
02d8b354
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.
Thường dùng trong data preprocessing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
9d90347e
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
026f0b62
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
bc8f2fe5
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Fibonacci recursive. Chậm nhưng minh họa recursion.
Thường dùng trong data preprocessing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
e94c249d
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
ec6209d6
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
35cec80d
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.
Thường dùng trong data preprocessing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
dae7b3c0
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3212e10d
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.
Thường dùng trong data preprocessing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
df937b48
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
25ab19ed
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
c8281c3e
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
84660575
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.
Thường dùng trong data preprocessing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
fab90207
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
4b927903
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.
Thường dùng trong data preprocessing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
6ee058d1
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
670b6252
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
6ee9fbea
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.
Thường dùng trong data preprocessing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
6074764d
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
b8c8a49e
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
b3d0f5df
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
ff04aa1d
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
a8865653
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
6900bdac
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.
Thường dùng trong data preprocessing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
d4bd559c
# File I/O def read_file(path): with open(path) as f: return f.read()
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
f37bf3cc
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
6db98338
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
d77f170f
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.
Thường dùng trong data preprocessing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
0faec863
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
3c18c598
def count_chars(text): return {c: text.count(c) for c in set(text)}
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
4df368ea
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
68133987
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
e00d489b
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
eb08f6cf
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
dd49fe31
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d0870f1d
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
da17b59e
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
3c235512
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
a2c8f5af
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
482b9cc4
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
44bf3459
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Base class cơ bản. **kwargs để flexible initialization.
Thường dùng trong data preprocessing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
5ef01765
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
4099e1b7
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.
Thường dùng trong data preprocessing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
349dbfd5
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
bff73401
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.
Thường dùng trong data preprocessing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
9b83099d
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
fa2c75cd
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.
Thường dùng trong data preprocessing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
3b618fd3
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
5bab26f8
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.
Thường dùng trong data preprocessing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
e67ae0f2
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
6634463d
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7164ebff
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.
Thường dùng trong data preprocessing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
4b46d308
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
7c5c85f4
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
7fb518fd
# 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.
Thường dùng trong data preprocessing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
a3a422f8
# 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.
Thường dùng trong data preprocessing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
79339459
# 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.
Thường dùng trong data preprocessing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
6f469914
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.
Thường dùng trong data preprocessing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
39640532
# File I/O def read_file(path): with open(path) as f: return f.read()
Fetch data từ API endpoint. Trả về JSON.
Thường dùng trong data preprocessing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]