How to use 'python print in columns' in Python

Every line of 'python print in columns' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17def print_columns(items):
18 """Print a list as multiple columns instead of just one."""
19 rows = []
20 items_per_column = int(len(items) / 4) + 1
21 for index, pokemon in enumerate(items):
22 name = pokemon.get_id() + " " + pokemon.get_name().title()
23 name = name.ljust(20)
24 if len(rows) < items_per_column:
25 rows.append(name)
26 else:
27 rows[index % items_per_column] += name
28 print_list(rows)

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

Related snippets