#!/usr/bin/env python3
#!/bin/bash

import operator
import sys
import pprint as pp
import re as replace

def check_upper(c):
    if c >= 'A' and c <= 'Z':
        return True
    else:
        return False

arguments = sys.argv[1:]

filename = arguments[0]
aantal_woorden = 0

dict = {}
capitaldict = {}
totaldict = {}

with open(filename, 'r') as file:
    for line in file:
        woorden = line.split(' ')

        for woord in woorden:
            woord = woord.strip()
            if (check_upper(woord)):
                if woord in capitaldict:
                    capitaldict[woord] += 1
                    print ("test")
                else:
                    capitaldict[woord] = 1

                if woord in totaldict:
                    totaldict[woord] += 1
                else:
                    totaldict[woord] = 1

            else:
                if woord in dict:
                    dict[woord] += 1
                else:
                    dict[woord] = 1

                if woord in totaldict:
                    totaldict[woord] += 1
                else:
                    totaldict[woord] = 1

print("These are the words without capitalletters")
for key, value in sorted(dict.items(), key=lambda kv: kv[1]):
   print("{:>10},{:>10}".format(key, value))

print("These are the words with capitalletters")
for key, value in sorted(capitaldict.items(), key=lambda kv: kv[1]):
    print("{:>10},{:>10}".format(key, value))

print("These are the total number of words")
for key, value in sorted(totaldict.items(), key=lambda kv: kv[1]):
    print("{:>10},{:>10}".format(key, value))
