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 |
|---|---|---|---|---|---|---|---|---|
22d81dfa | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Base class cơ bản. **kwargs để flexible initialization. | Grouping là common operation trong data analysis. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
6a457234 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Base class cơ bản. **kwargs để flexible initialization. | Grouping là common operation trong data analysis. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
1bb730b3 | 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. | Grouping là common operation trong data analysis. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
3e8c015e | # 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
eb5fac51 | # 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. | Grouping là common operation trong data analysis. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
1dd78b4a | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Base class cơ bản. **kwargs để flexible initialization. | Grouping là common operation trong data analysis. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
e66adbd2 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Base class cơ bản. **kwargs để flexible initialization. | Grouping là common operation trong data analysis. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
5f615d8c | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Base class cơ bản. **kwargs để flexible initialization. | Grouping là common operation trong data analysis. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
c573426b | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Base class cơ bản. **kwargs để flexible initialization. | Grouping là common operation trong data analysis. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
3ed4e0de | # 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
0cf86d3f | 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. | Grouping là common operation trong data analysis. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
3e55ce00 | # 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. | Grouping là common operation trong data analysis. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
df782248 | 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
e86eafa1 | # 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. | Grouping là common operation trong data analysis. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
1aff3dad | 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. | Grouping là common operation trong data analysis. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
88221a21 | # 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
f4ac5819 | 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. | Grouping là common operation trong data analysis. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
0518c435 | # 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. | Grouping là common operation trong data analysis. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
f3c60dbe | # 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
9652d5fd | 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. | Grouping là common operation trong data analysis. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
187501a9 | # 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. | Grouping là common operation trong data analysis. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
8da587e6 | # 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
dd3886b4 | # 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. | Grouping là common operation trong data analysis. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
d7ad0bd3 | # 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. | Grouping là common operation trong data analysis. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
124a87c9 | # 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
4864f86b | 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. | Grouping là common operation trong data analysis. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
83bf6b2f | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
30d34c26 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
7b02499e | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
a8b2d1ad | 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. | Grouping là common operation trong data analysis. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
16c5da1a | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
73b26443 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
28fc9d5c | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
e3b2cbc3 | 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
a989358c | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
82932cb5 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
06513b8a | 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. | Grouping là common operation trong data analysis. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
9637bb5d | # 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. | Grouping là common operation trong data analysis. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
5af38fc8 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
0edd4dd0 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
cd5f0d89 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
9627a28b | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
4b4f6538 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Fetch data từ API endpoint. Trả về JSON. | Grouping là common operation trong data analysis. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
fdac4c60 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
8a511ba1 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
85c8610d | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
c4f4ed3e | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
d259b781 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
0eb648cc | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | intermediate | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
a8d7edc8 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | advanced | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
9f7ea4fb | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | beginner | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
dbc5e39f | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | intermediate | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
08cc06fa | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | advanced | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
9b9336e3 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | beginner | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
36d49d80 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | intermediate | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
127489f7 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | advanced | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
9a3c7b95 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | beginner | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
9051ba77 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | intermediate | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
72a2569a | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | advanced | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
064da32b | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Extract emails từ text dùng regex pattern. | Grouping là common operation trong data analysis. | python | beginner | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
8be28b7f | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | intermediate | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
9605dbec | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | advanced | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
1ce10597 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | beginner | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
f56851f2 | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | intermediate | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
33bf83d2 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | advanced | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
2ea0d7e3 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | beginner | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
fc382897 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | intermediate | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
067e8b0e | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | advanced | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
c0760f37 | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | beginner | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
a4f9bee7 | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | intermediate | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
76ee661e | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | advanced | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
c4deb0f0 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | beginner | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
9d510dfe | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | intermediate | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
9c5a8924 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | advanced | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
38da47fe | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | beginner | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
5aa2546d | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | intermediate | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
d5e372b5 | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Load JSON từ file. Trả về parsed object. | Grouping là common operation trong data analysis. | python | advanced | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
6d0846c3 | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | beginner | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
8abcaede | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | intermediate | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
21a0e5ea | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | advanced | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
07061622 | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | beginner | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
7e199a28 | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | intermediate | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
862d88d2 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | advanced | [
"dict",
"counting"
] | 3.9+ | [
"python",
"function",
"example"
] |
de5307c5 | # Lists & Dicts
def flatten(nested):
return [item for sublist in nested for item in sublist] | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | beginner | [
"list",
"flattening"
] | 3.9+ | [
"python",
"function",
"example"
] |
f92921f7 | def merge_dicts(*dicts):
return {k:v for d in dicts for k,v in d.items()} | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | intermediate | [
"dict",
"merging"
] | 3.9+ | [
"python",
"function",
"example"
] |
b63f79cf | # Error Handling
def safe_int(value, default=0):
try: return int(value)
except: return default | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | advanced | [
"error-handling",
"type-conversion"
] | 3.9+ | [
"python",
"function",
"example"
] |
4ff4f3ce | # Algorithms
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | beginner | [
"recursion",
"algorithm"
] | 3.9+ | [
"python",
"function",
"example"
] |
5e0922e8 | def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5)+1)) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | intermediate | [
"algorithm",
"math"
] | 3.9+ | [
"python",
"function",
"example"
] |
9de9bef1 | # OOP
class BaseModel:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def to_dict(self):
return self.__dict__ | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | advanced | [
"class",
"oop"
] | 3.9+ | [
"python",
"function",
"example"
] |
1f85e877 | # Decorators
def log_calls(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__}")
return func(*args, **kwargs)
return wrapper | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | beginner | [
"decorator",
"function"
] | 3.9+ | [
"python",
"function",
"example"
] |
94dcbb33 | # Working with APIs
def fetch_data(url):
import requests
return requests.get(url).json() | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | intermediate | [
"api",
"http"
] | 3.9+ | [
"python",
"function",
"example"
] |
ecd494a9 | # Regular Expressions
def extract_emails(text):
import re
return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | advanced | [
"regex",
"pattern-matching"
] | 3.9+ | [
"python",
"function",
"example"
] |
8eed7a58 | # JSON Operations
def load_json(path):
with open(path) as f: return json.load(f) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | beginner | [
"json",
"file-io"
] | 3.9+ | [
"python",
"function",
"example"
] |
6d46734f | def save_json(path, data):
with open(path, 'w') as f: json.dump(data, f) | Save data thành JSON file. | Grouping là common operation trong data analysis. | python | intermediate | [
"io",
"file-operations"
] | 3.9+ | [
"python",
"function",
"example"
] |
abee715f | # File I/O
def read_file(path):
with open(path) as f: return f.read() | Hàm này đọc nội dung của file và trả về dưới dạng string. | String manipulation dùng .split() và slicing. | python | advanced | [
"file-io",
"context-manager"
] | 3.9+ | [
"python",
"function",
"example"
] |
c2bb6576 | def write_file(path, content):
with open(path, 'w') as f: f.write(content) | Hàm này đọc nội dung của file và trả về dưới dạng string. | String manipulation dùng .split() và slicing. | python | beginner | [
"list-processing",
"data-structures"
] | 3.9+ | [
"python",
"function",
"example"
] |
18f6e023 | # Data Processing
def process_data(items):
return [x.strip().lower() for x in items if x] | Hàm này đọc nội dung của file và trả về dưới dạng string. | String manipulation dùng .split() và slicing. | python | intermediate | [
"string",
"text-processing"
] | 3.9+ | [
"python",
"function",
"example"
] |
33f27e64 | def group_by_key(items, key):
result = {}
for item in items:
k = item.get(key)
if k not in result: result[k] = []
result[k].append(item)
return result | Hàm này đọc nội dung của file và trả về dưới dạng string. | String manipulation dùng .split() và slicing. | python | advanced | [
"grouping",
"dict"
] | 3.9+ | [
"python",
"function",
"example"
] |
40dc8c2e | # String Operations
def reverse_words(text):
return ' '.join(text.split()[::-1]) | Hàm này đọc nội dung của file và trả về dưới dạng string. | String manipulation dùng .split() và slicing. | python | beginner | [
"string",
"manipulation"
] | 3.9+ | [
"python",
"function",
"example"
] |
d4bd9018 | def count_chars(text):
return {c: text.count(c) for c in set(text)} | Hàm này đọc nội dung của file và trả về dưới dạng string. | String manipulation dùng .split() và slicing. | python | intermediate | [
"dict",
"counting"
] | 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.