Sharing an example using pprint module (Pretty Printing) Thanks.

1 #!/usr/bin/env python3.6
2
3 # Julian Vargas
4 # Oct 31, 2018.
5
6 # The program counts vowels in a string.
7 # It utilizes pprint module (Pretty Printing) with
8 # dictionary's values.
9 import pprint
10
11 message = "It was a bright cold day in April, and the clocks were striking thirteen."
12 count = {}
13
14 for vowel in message:
15 if vowel in "AEIOUaeiou":
16 count.setdefault(vowel, 0)
17 count[vowel] = count[vowel] + 1
18
19 print()
20 # lines 20 and 21 are equivalent to each other.
21 #pprint.pprint(count)
22 print(pprint.pformat(count))
23 print()
Happy Python programming.
  • post-author-pic
    Michael M
    11-01-2018

    Hello,


    Thanks for sharing that!

  • post-author-pic
    Craig A
    11-01-2018

    Thanks, Jose!

  • post-author-pic
    Keith T
    11-01-2018

    Thanks for sharing, I'm sure people will find this helpful.

Looking For Team Training?

Learn More