Q:

Get the sum by file extensions in python

Newbie question here!
I'm trying to get the sum of file sizes by file extension in a directory. So far I'm using a modified version of this (via Python - Acquiring a count of file extensions across all directories) to count them. 
Trying to use os.path.getsize() then use sum() to add them up, but I either get zero or errors.
What am I missing?
The code I copied is this:
import os
import collections
extensions = collections.defaultdict(int)

place = input('Type the directory path: ')

for path, dirs, files in os.walk(place):
   for filename in files:
       extensions[os.path.splitext(filename)[1].lower()] += 1

for key,value in extensions.items():
    print ('Extension: ', key, ' ', value, ' items')

A:

Did you try this?
import os
import collections
extensions = collections.defaultdict(int)
size = collections.defaultdict(int)

for path, dirs, files in os.walk('/'):
   for filename in files:
       extensions[os.path.splitext(filename)[1].lower()] += 1
       size[os.path.splitext(filename)[1].lower()] += os.path.getsize(path+os.sep+filename)

for key,value in extensions.items():
    print 'Extension: ', key, ' ', value, ' items'

for key,value in size.items():
    print 'Extension: ', key, ' ', value, ' size'

this is based on your link

