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 |
|---|---|---|---|---|---|---|---|---|
d1b3cfa8 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
21741eb7 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
05fad318 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Base class cơ bản. **kwargs để flexible initialization. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
18acef1e | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Base class cơ bản. **kwargs để flexible initialization. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
bf956516 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Base class cơ bản. **kwargs để flexible initialization. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
38811ce6 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Base class cơ bản. **kwargs để flexible initialization. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
6e0867f8 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
b547e44d | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
6b6c37ac | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
de605de2 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
9a3dee76 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
6333981e | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
697d5b11 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
805cfdb8 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
2d62f5e4 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
53f82e4a | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
13dc10f7 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
de031bab | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
22487d39 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
b8c11c11 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
91059e35 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
3178f599 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
b9599dee | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
be347e5e | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
f53e5928 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
5620cfb9 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
858ebff2 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
53f8dc9e | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
6e1ec4e8 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
b5e23faf | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
6a5039c6 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
d13257f5 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
30779ca2 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
f72e9f10 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
af85c4a2 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
f25199ae | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
4b302810 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
de91a4c9 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
5b76622e | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
ccc51d56 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Fetch data từ API endpoint. Trả về JSON. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
453a9dfb | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Extract emails từ text dùng regex pattern. | 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"
] |
f9bea694 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Extract emails từ text dùng regex pattern. | 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"
] |
9f5bc7c7 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Extract emails từ text dùng regex pattern. | 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"
] |
8f7c5ac1 | 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. | 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"
] |
40c9c061 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Extract emails từ text dùng regex pattern. | 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"
] |
1d3ba372 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Extract emails từ text dùng regex pattern. | 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"
] |
a82e4f7b | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Extract emails từ text dùng regex pattern. | 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"
] |
6793d050 | 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. | 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"
] |
f0e25dff | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Extract emails từ text dùng regex pattern. | 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"
] |
beeb1a69 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Extract emails từ text dùng regex pattern. | 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"
] |
ee6c1ed0 | 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. | 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"
] |
9513bc68 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
8905d70d | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
4878bbcb | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Extract emails từ text dùng regex pattern. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
96ddde0c | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Extract emails từ text dùng regex pattern. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
7e4e45fb | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Extract emails từ text dùng regex pattern. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
43c601e3 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Extract emails từ text dùng regex pattern. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
ec480f57 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
10f38c6d | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
b4e0cf56 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
fbfb6571 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
ac4843c1 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
b60d2fc9 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
a7babc5f | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
d56a7c02 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
03d23245 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
13b7b3d5 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
d1da87f4 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
8e719d3d | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
b8433673 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
04161d0f | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
47021180 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
bb65bf92 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
e47ab3af | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Load JSON từ file. Trả về parsed object. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
dfcf33d2 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
557b808b | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
1bf76f62 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
ba3c80b4 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
1c54dfc4 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
6a94a176 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
8ca0f721 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
9242f87b | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
f07ea2f4 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
5bde621c | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
16f07f15 | 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
38e4e3ea | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
e0c5af49 | # 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. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
404741c6 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
6adce422 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
397b8f90 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
6433e4d3 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Save data thành JSON file. | Ghi nội dung mới vào file, overwrite nếu tồn tại. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
50543ab6 | # 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. | Thường dùng trong data preprocessing. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
a65e9aea | 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. | Thường dùng trong data preprocessing. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
b0c5181b | # 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. | Thường dùng trong data preprocessing. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
ebca057e | 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. | Thường dùng trong data preprocessing. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
45952462 | # 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. | Thường dùng trong data preprocessing. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
91376aa1 | 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. | Thường dùng trong data preprocessing. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
51f65334 | # 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. | Thường dùng trong data preprocessing. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
d60452c1 | 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. | Thường dùng trong data preprocessing. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
3d43b5b5 | # 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. | Thường dùng trong data preprocessing. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.