Here's how to count and align:
sentence = 'This is a random sentence, if a random sentence is what you want' slist = sentence.split() counts = {i:slist.count(i) for i in slist} for key, value in counts.items(): print('{:>10} {:>10}'.format(key, value))results:
Output: This 1
is 2
a 2
random 2
sentence, 1
if 1
sentence 1
what 1
you 1
want 1
Or for left aligned text:sentence = 'This is a random sentence, if a random sentence is what you want' slist = sentence.split() counts = {i:slist.count(i) for i in slist} for key, value in counts.items(): print('{:<10} {:<10}'.format(key, value))
Output:This 1
is 2
a 2
random 2
sentence, 1
if 1
sentence 1
what 1
you 1
want 1