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
beb43873
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
57f5faec
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
8ee1173f
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
d72ffa95
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
d9115858
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
b8c4e226
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
7334ad45
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
7145780e
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
9035d752
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Xử lý danh sách: strip spaces, convert to lowercase, filter empty.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
cc371876
# File I/O def read_file(path): with open(path) as f: return f.read()
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
1f1bbd07
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
6cebdcb0
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
12e07252
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
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
7253cce2
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
7a30e207
def count_chars(text): return {c: text.count(c) for c in set(text)}
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
43bcb063
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
7eb77cfb
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
bc294875
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
dbe59f47
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
7bbf869e
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
4544c618
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
9e0d9084
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
68512291
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
a490e8e3
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
93153124
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
9334003e
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Nhóm items theo key. Tạo dictionary với key là group, value là list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
6a59dced
# File I/O def read_file(path): with open(path) as f: return f.read()
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
3a801f14
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
d1e17787
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
0fa97f53
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
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
ac44334b
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
7f0a2838
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
40547509
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
4b7ae68b
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
f679eec0
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
f7036d5e
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
447d581d
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
cfebca6e
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
98d1fb61
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
ea72c09e
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
4ff64e6a
# Regular Expressions def extract_emails(text): import re return re.findall(r'[\w\.-]+@[\w\.-]+\.\w+', text)
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
bad45e10
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
6112b525
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Đảo ngược thứ tự các từ trong text.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
fdbfbdd7
# File I/O def read_file(path): with open(path) as f: return f.read()
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
fff188d4
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
7bfa6d82
# Data Processing def process_data(items): return [x.strip().lower() for x in items if x]
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
d7372ce2
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
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
c125e185
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
b887a16b
def count_chars(text): return {c: text.count(c) for c in set(text)}
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
e7e432fe
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
32ccaf5b
def merge_dicts(*dicts): return {k:v for d in dicts for k,v in d.items()}
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
ec4ed765
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
6b50f35c
# Algorithms def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
969c53a5
def is_prime(n): return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
ee4b6321
# OOP class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) def to_dict(self): return self.__dict__
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
d9d0d921
# Decorators def log_calls(func): def wrapper(*args, **kwargs): print(f"Calling {func.__name__}") return func(*args, **kwargs) return wrapper
Đếm tần suất xuất hiện của mỗi ký tự.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
8e2c8439
# 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ự.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
7df26fe5
# 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ự.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
af809817
# 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ự.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
277a396d
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ự.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
4d1b6a46
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
a0dc1408
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Làm phẳng list nested thành flat list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
f7b885e7
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
695bf9de
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
92b52047
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Làm phẳng list nested thành flat list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
a9c54a0f
def count_chars(text): return {c: text.count(c) for c in set(text)}
Làm phẳng list nested thành flat list.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
681ad387
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
50282c02
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
1cd8fbbd
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
407b4fb1
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
da1fcb6b
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
9526b25d
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
a4b8daf5
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
d2a7c26b
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Làm phẳng list nested thành flat list.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
af0088ad
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
3f04ca3a
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
caf8ae9c
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
aa34eaa2
# File I/O def read_file(path): with open(path) as f: return f.read()
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
c665aa57
def write_file(path, content): with open(path, 'w') as f: f.write(content)
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
06cc1c22
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
1533bfc8
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
7222a7c0
# String Operations def reverse_words(text): return ' '.join(text.split()[::-1])
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
04c5b87d
def count_chars(text): return {c: text.count(c) for c in set(text)}
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]
5023732e
# Lists & Dicts def flatten(nested): return [item for sublist in nested for item in sublist]
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list", "flattening" ]
3.9+
[ "python", "function", "example" ]
34e74be6
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "merging" ]
3.9+
[ "python", "function", "example" ]
577c5c79
# Error Handling def safe_int(value, default=0): try: return int(value) except: return default
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "error-handling", "type-conversion" ]
3.9+
[ "python", "function", "example" ]
dc1f9f79
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "recursion", "algorithm" ]
3.9+
[ "python", "function", "example" ]
1019332b
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "algorithm", "math" ]
3.9+
[ "python", "function", "example" ]
1d1656a5
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "class", "oop" ]
3.9+
[ "python", "function", "example" ]
6c176580
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "decorator", "function" ]
3.9+
[ "python", "function", "example" ]
b8306267
# Working with APIs def fetch_data(url): import requests return requests.get(url).json()
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "api", "http" ]
3.9+
[ "python", "function", "example" ]
cab2f4de
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "regex", "pattern-matching" ]
3.9+
[ "python", "function", "example" ]
9d2bb7b7
# JSON Operations def load_json(path): with open(path) as f: return json.load(f)
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "json", "file-io" ]
3.9+
[ "python", "function", "example" ]
15ce99a2
def save_json(path, data): with open(path, 'w') as f: json.dump(data, f)
Gộp nhiều dictionaries thành một.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "io", "file-operations" ]
3.9+
[ "python", "function", "example" ]
e4a24056
# 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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "file-io", "context-manager" ]
3.9+
[ "python", "function", "example" ]
d19267d8
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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "list-processing", "data-structures" ]
3.9+
[ "python", "function", "example" ]
5df98639
# 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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "string", "text-processing" ]
3.9+
[ "python", "function", "example" ]
8e3d1406
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.
Counter pattern rất hữu ích trong text processing.
python
advanced
[ "grouping", "dict" ]
3.9+
[ "python", "function", "example" ]
89fca278
# 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.
Counter pattern rất hữu ích trong text processing.
python
beginner
[ "string", "manipulation" ]
3.9+
[ "python", "function", "example" ]
280794d8
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.
Counter pattern rất hữu ích trong text processing.
python
intermediate
[ "dict", "counting" ]
3.9+
[ "python", "function", "example" ]