Nan Hua
Nan Hua

Reputation: 3664

Look alternative to pprint for printing in Python

As we know, pprint can be "annoying" when it's printing list of a lot of small words, since pprint can only accept of two modes: one-line of multiple small words, or multiple lines of small words on each line separately.

Is there some other python library which can print the dict like {"1" : [1] * 10, "2": [2]*100} in a pretty while still compact way?

Thanks!

Upvotes: 1

Views: 1017

Answers (1)

skrx
skrx

Reputation: 20438

Pass True as the compact argument. (Only available in Python 3.4+)

>>> pprint({"1" : [1]*10, "2": [2]*100}, compact=True)
{'1': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
 '2': [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2]}

Upvotes: 2

Related Questions