Given a string and a character, write a Python function to count the number of occurrences of the character in the string.
def count_characters(string, char):
    return sum([1 for x in string if x == char])