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 |
|---|---|---|---|---|---|---|---|---|
40f32176 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Đếm tần suất xuất hiện của mỗi ký tự. | 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"
] |
06a4d141 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Đếm tần suất xuất hiện của mỗi ký tự. | 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"
] |
30ae7132 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Đếm tần suất xuất hiện của mỗi ký tự. | 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"
] |
6cc37e79 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Đếm tần suất xuất hiện của mỗi ký tự. | 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"
] |
a88236bc | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Làm phẳng list nested thành flat list. | 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"
] |
5204cb3f | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Làm phẳng list nested thành flat list. | 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"
] |
49fc09ce | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Làm phẳng list nested thành flat list. | 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"
] |
b41e93f3 | 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 | Làm phẳng list nested thành flat list. | 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"
] |
7d34f276 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Làm phẳng list nested thành flat list. | 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"
] |
e1b4ee76 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Làm phẳng list nested thành flat list. | 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"
] |
641a9c54 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Làm phẳng list nested thành flat list. | 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"
] |
145f16cb | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Làm phẳng list nested thành flat list. | 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"
] |
50aebda2 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Làm phẳng list nested thành flat list. | 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"
] |
62a25b68 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Làm phẳng list nested thành flat list. | 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"
] |
6406cb30 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Làm phẳng list nested thành flat list. | 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"
] |
1ba0a1ea | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Làm phẳng list nested thành flat list. | 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"
] |
aa4d8cbe | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Làm phẳng list nested thành flat list. | 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"
] |
fdace4bc | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Làm phẳng list nested thành flat list. | 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"
] |
f1b46f77 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Làm phẳng list nested thành flat list. | 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"
] |
c3fc9065 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Làm phẳng list nested thành flat list. | 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"
] |
f8793f64 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Làm phẳng list nested thành flat list. | 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"
] |
24dcb850 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Gộp nhiều dictionaries thành một. | 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"
] |
8ce2e96e | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Gộp nhiều dictionaries thành một. | 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"
] |
bee6e9ce | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Gộp nhiều dictionaries thành một. | 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"
] |
1234cca5 | 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. | 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"
] |
018e33bd | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Gộp nhiều dictionaries thành một. | 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"
] |
dffa1b0c | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Gộp nhiều dictionaries thành một. | 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"
] |
6295ec20 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Gộp nhiều dictionaries thành một. | 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"
] |
e8ec798d | 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. | 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"
] |
1656b355 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Gộp nhiều dictionaries thành một. | 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"
] |
7e39d9ed | # 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. | 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"
] |
1a299689 | 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. | 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"
] |
23367325 | # 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. | 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"
] |
9d83c2c5 | # 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. | 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"
] |
592452bc | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Gộp nhiều dictionaries thành một. | 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"
] |
5bcca4c4 | # 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. | 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"
] |
21b080aa | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Gộp nhiều dictionaries thành một. | 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"
] |
218df9b9 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Gộp nhiều dictionaries thành một. | 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"
] |
a8a561ce | # 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. | 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"
] |
63c4a14e | 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. | 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"
] |
f5de9378 | # 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. | 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"
] |
4062d0de | 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. | 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"
] |
b67220fb | # 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. | 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"
] |
a0e6d72a | 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. | 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"
] |
9c0ca951 | # 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. | 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"
] |
27962c6e | 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. | 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"
] |
ba993ad0 | # 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. | 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"
] |
7f0927f5 | # 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. | 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"
] |
c80c52cb | 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. | 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"
] |
edfa8019 | # 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. | 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"
] |
0f5247bf | # 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. | 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"
] |
4954d499 | # 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. | 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"
] |
51b4f10a | # 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. | 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"
] |
d681211d | # 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. | 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"
] |
3193c59c | 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. | 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"
] |
d498327e | # 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. | 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"
] |
43e58a94 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Fibonacci recursive. Chậm nhưng minh họa recursion. | 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"
] |
e36b77f7 | # 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. | 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"
] |
ba4dab27 | 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. | 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"
] |
368c02a9 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Fibonacci recursive. Chậm nhưng minh họa recursion. | 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"
] |
cff9b092 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Fibonacci recursive. Chậm nhưng minh họa recursion. | 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"
] |
2748154b | # 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. | 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"
] |
e003e049 | 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. | 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"
] |
1319487d | # 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. | 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"
] |
e2802121 | # 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. | 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"
] |
db659f13 | 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. | 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"
] |
206090d0 | # 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. | 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"
] |
33a729fd | # 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. | 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"
] |
00205606 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Fibonacci recursive. Chậm nhưng minh họa recursion. | 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"
] |
5bd6751f | # 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. | 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"
] |
bedf514d | # 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. | 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"
] |
32568a0f | 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. | 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"
] |
b8cfa343 | # 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. | 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"
] |
c19795c0 | 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. | 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"
] |
1ddfa802 | # 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. | 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"
] |
c3a02b53 | 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. | 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"
] |
6a114621 | # 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. | 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"
] |
0ac4cec4 | 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. | 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"
] |
c1c51a8b | # 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. | 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"
] |
4de5c13a | 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. | 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"
] |
5bdf126b | # 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. | 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"
] |
1dc49518 | # 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. | 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"
] |
b87dd84e | 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. | 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"
] |
6b8a7b34 | # 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. | 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"
] |
ede0d0af | # 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. | 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"
] |
44f1babf | # 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. | 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"
] |
891c8a29 | # 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. | 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"
] |
2de4be5e | # 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. | 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"
] |
1d74b6e6 | 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. | 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"
] |
00f4f65a | # File I/O
def read_file(path):
with open(path) as f: return f.read() | 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 | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
bee65378 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | 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 | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
91ecfe8d | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | 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 | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
e883dc47 | 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. | 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"
] |
4bf6fe9d | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | 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 | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
5b59412b | def count_chars(text):
return {c: text.count(c) for c in set(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 | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
b1bd1498 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | 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 | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
21f0eadf | 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. | 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"
] |
f20151ba | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | 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 | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
00f3b1b6 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | 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 | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
ca82d1c0 | 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. | 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"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.