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
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
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