Results for “pack”
Small, practical examples. Search by task or narrow things down below.
Remove duplicates from a list
Remove repeated hashable values while preserving the order in which they first appeared.
list✓ Tested
Replace text in a string
Replace every occurrence of a substring and keep the result in a new string. The original string is unchanged.
string✓ Tested
Sort dictionaries by a value
Sort a list of dictionaries by a numeric field, leaving the original list unchanged.
sort✓ Tested
Split a string into words
Split text on whitespace, automatically treating repeated spaces, tabs, and line breaks as a single separator.
string✓ Tested
Write a JSON file
Save a dictionary as readable, indented JSON while preserving Unicode characters.
json✓ Tested
Write a text file
Save a string to a UTF-8 text file and close the file automatically when the write finishes.
file✓ Tested
Write dictionaries to CSV
Write a list of dictionaries to a CSV file with a header row and a predictable column order.
csv✓ Tested