Q:

PYTHON CHALLENGE: Creating a program that processes .txt file and counts # of occurrences of each character

I've already programmed code that accomplishes this task by doing something along the lines of 
import collections
def main():
    c = collections.Counter()
    inFile = open("Text.txt", 'r')
    for line in inFile:
        c += collections.Counter(line)
    for key in c:
        print(key, "character occurs", c[key], "times.")
    inFile.close()
main()

This code accomplishes the task, BUT, it contains 10 lines of executable code - I need to find a way to do this in 4 lines of code or less... Lines of code include module imports, function definitions, and function calls. It is NOT okay to compress programming structures to make code fit on fewer lines:
Ex: 
for i in range(20): code...
def main(): code ....

I can't for the life of me figure this out. Anyone have any ideas?

A:

Okay, starting with your code:
import collections
def main():
    c = collections.Counter()
    inFile = open("Text.txt", 'r')
    for line in inFile:
        c += collections.Counter(line)
    for key in c:
        print(key, "character occurs", c[key], "times.")
    inFile.close()
main()

We can remove the main function and call:
import collections
c = collections.Counter()
inFile = open("Text.txt", 'r')
for line in inFile:
    c += collections.Counter(line)
for key in c:
    print(key, "character occurs", c[key], "times.")
inFile.close()

This nets us 2 lines -- down to 8.  We can also use a with context manager to save a line on the file closing:
import collections
c = collections.Counter()
with open("Text.txt", 'r') as inFile:
    for line in inFile:
        c += collections.Counter(line)
    for key in c:
        print(key, "character occurs", c[key], "times.")

Down to 7.  We can also create a single Counter object, initialized over the entire file contents, instead of creating one and updating it with values from each line:
import collections
with open("Text.txt", 'r') as inFile:
    c = collections.Counter(inFile.read())
    for key in c: 
        print(key, "character occurs", c[key], "times.")

Down to 5.  We can also cheat and put that last for loop and body on the same line:
import collections
with open("Text.txt", 'r') as inFile:
    c = collections.Counter(inFile.read())
    for key in c: print(key, "character occurs", c[key], "times.")

Which gives us 4 lines, but it may violate the "It is NOT okay to compress programming structures to make code fit on fewer lines" rule.  We can be less cheaty by doing something like:
import collections
with open("Text.txt", 'r') as inFile:
    c = collections.Counter(inFile.read())
    print('\n'.join("{!r} character occurs {} times".format(k,v) for k,v in c.items()))

It's not the prettiest, but it's 4 lines.

Of course you could go further, skipping the creation of the intermediary c object:
import collections
with open("Text.txt", 'r') as inFile:
    print('\n'.join("{!r} character occurs {} times".format(k,v) for k,v in collections.Counter(inFile.read()).items()))

And if you didn't care about closing the file:
import collections
print('\n'.join("{!r} character occurs {} times".format(k,v) for k,v in collections.Counter(open("Text.txt", 'r').read()).items()))

To go to 1 line with an import you could use the creative (and crazy) solution suggested by Kevin in the comments.

