Avec python vous pouvez utiliser le module pprint — Data pretty printer pour afficher une liste ou un dictionnaire sur plusieurs lignes ce qui rend la lecture plus facile, illustration:
import pprint# Example with a list:list = ['Bob', 'Robert', 'Lindsay', 'Kate']print listpprint.pprint(list, width=1)# Example with a dictionary:dic = {'Bob': 25, 'Robert': 46, 'Lindsay': 54, 'Kate': 13}print dicpprint.pprint(dic, width=1)
donne
['Bob', 'Robert', 'Lindsay', 'Kate']['Bob','Robert','Lindsay','Kate']{'Bob': 25, 'Kate': 13, 'Robert': 46, 'Lindsay': 54}{'Bob': 25,'Kate': 13,'Lindsay': 54,'Robert': 46}
Recherches associées
| Liens | Site |
|---|---|
| pprint — Data pretty printer | python doc |
| python pprint dictionary on multiple lines | stackoverflow |
| How to use pprint to print an object using the built-in str(self) method? | stackoverflow |
