Printing zip() with Asterisk (*) – Clean Output Techniques in Data Science 2026
When working with zip(), you often want to print the paired values in a clean, readable format. Using the asterisk (*) with print() is a powerful and Pythonic way to achieve this without manual loops or string formatting.
TL;DR — The Power Pattern
print(*zip(list1, list2))– Prints tuples directlyfor a, b in zip(...):– Traditional unpackingprint(*[f"{a} → {b}" for a, b in zip(...)])– Formatted output
1. Basic Printing with zip() and Asterisk
names = ["Alice", "Bob", "Charlie"]
scores = [85, 92, 78]
regions = ["North", "South", "East"]
# Simple zip output
print(*zip(names, scores, regions), sep="\n")
# Output:
# ('Alice', 85, 'North')
# ('Bob', 92, 'South')
# ('Charlie', 78, 'East')
2. Clean Formatted Output Using Asterisk
# Most readable way - formatted strings with unpacking
for name, score, region in zip(names, scores, regions):
print(f"{name:10} | Score: {score:3} | Region: {region}")
# One-liner using asterisk (advanced)
print(*[f"{name:10} | {score:3} | {region}"
for name, score, region in zip(names, scores, regions)],
sep="\n")
3. Real-World Data Science Example
import pandas as pd
# Create a small demo file so this example runs as-is
# (in your project, sales_data.csv is your real export)
import numpy as np
rng = np.random.default_rng(42)
n = 60
pd.DataFrame({
"order_id": range(1001, 1001 + n),
"order_date": pd.date_range("2026-01-01", periods=n, freq="3D"),
"customer_id": rng.integers(101, 121, n),
"customer_name": rng.choice([" ana", "ben ", "chen", "dana"], n),
"product_id": rng.integers(1, 9, n),
"region": rng.choice(["North", "South", "East", "West"], n),
"category": rng.choice(["Electronics", "Computers", "Books", "Home"], n),
"payment_method": rng.choice(["card", "cash", "wallet"], n),
"segment": rng.choice(["consumer", "business"], n),
"quantity": rng.integers(1, 6, n),
"amount": rng.uniform(50, 2500, n).round(2),
"discount": rng.choice([0.0, 0.05, 0.1, 0.2], n),
}).assign(
price=lambda d: (d["amount"] / d["quantity"]).round(2),
profit=lambda d: (d["amount"] * rng.uniform(0.05, 0.3, n)).round(2),
).assign(
ship_date=lambda d: d["order_date"] + pd.Timedelta(days=2),
status=lambda d: np.where(d["amount"] > 2000, "priority", "standard"),
).to_csv("sales_data.csv", index=False)
df = pd.read_csv("sales_data.csv")
# Print top 5 highest sales with their details using zip + asterisk
top_sales = df.nlargest(5, "amount")
print("Top 5 Sales:")
print("-" * 60)
print(*[f"#{i+1:2d} | ${row.amount:8.2f} | {row.region:8} | Customer {row.customer_id}"
for i, row in enumerate(top_sales.itertuples())],
sep="\n")
4. Best Practices in 2026
- Use
print(*zip(...), sep="\n")for quick debugging of paired data - Prefer list comprehensions with f-strings + asterisk for formatted output
- Use traditional
forloops with unpacking when logic inside the loop is complex - Always consider readability over clever one-liners in production code
- Combine with
enumerate()when you need ranking or numbering
Printing with zip and *
print accepts any number of arguments and separates them with sep, a space by default. Combining print with * lets you print every item of a sequence without a loop, and combining it with zip lets you print aligned pairs.
For tidy tables, use f-strings with width and alignment specifiers such as {name:<8} and {value:>8.2f}. These keep columns lined up regardless of value length.
print(*items, sep="\n") prints one item per line, a handy shortcut for quick inspection.
Worked Example: Quick and Formatted Output
The same data is printed with unpacking, with custom separators, and as an aligned table.
regions = ["North", "South", "East"]
totals = [1200.5, 450.0, 980.25]
print(*regions)
print(*regions, sep=" | ")
print(*zip(regions, totals))
print(f"{'region':<8}{'total':>10}")
for region, total in zip(regions, totals):
print(f"{region:<8}{total:>10.2f}")
The first lines are quick ways to look at data while exploring. The f-string table right-aligns the totals with two decimals, which is what you want in a report.
Common Mistakes
- Printing a list directly when separate items are clearer.
- Building strings with + inside loops.
- Forgetting width specifiers and getting ragged columns.
- Using print for logging in production code.
Quick Summary
- print(*seq) prints items separated by spaces.
- Use sep= to change separators.
- zip pairs values for printing.
- Use f-string widths for aligned tables.
Conclusion
Using the asterisk (*) with zip() is a powerful technique for printing paired or zipped data cleanly. In data science, this pattern is especially useful for displaying feature-value pairs, top-N results, or aligned data from multiple sources. While one-liners with asterisk can be elegant, always prioritize readability and maintainability in your final code.
Next steps:
- Practice printing zipped data using both the asterisk technique and traditional unpacking to see which style you prefer for different situations