Differences in word counts in two files How can I change my two functions to be more readable functions (i.e. in steps), because I am using pycharm.

import collections

def compute_word_importance(fpath1,fpath2):

    mylist1 = []
    mylist2 = []
    with open(fpath1, 'rt', encoding='UTF-8') as f:
        for line1 in f:
            for word in line1.split(" "):
                if word.strip('\n'):
                    mylist1.append(word.strip())
    with open(fpath2, 'rt', encoding='UTF-8') as x:
        for line2 in x:
            for word in line2.split(" "):
                if word.strip('\n'):
                    mylist2.append(word.strip())

    if mylist1==0 and mylist2==0:
        return None

    c=collections.Counter(mylist1)
    c.subtract(mylist2)
    return c
Change lines like this:

    for word in line1.split(" "):


To lines like:

    for word in (w.strip() for w in line1.split(" ")):


UPDATE:

Here are two ways you could tighten up your function:

1:

    def compute_word_importance(fpath1,fpath2):

        count = collections.Counter()
        with open(fpath1, 'rt', encoding='UTF-8') as fp:
            for line in f:
                count.update([w.strip() for word in line.split()])
        with open(fpath2, 'rt', encoding='UTF-8') as fp:
            for line in fp:
                count.subtract([w.strip() for word in line.split()])

        return len(counter) and counter or none


2:

    def compute_word_importance(fpath1,fpath2):

        def get_words(path):
            words = []
            with open(path, 'rt', encoding='UTF-8') as fp:
                for line1 in f:
                    words.extend([w.strip() for word in line.split()])

        counter = collections.Counter(get_words(fpath1))
        counter.subtract(get_words(fpath2))

        return len(counter) and counter or none