input: Write a python function to generate text based on given grammar rules.
  assert generate_text({'S': ['NP VP', 'VP'], 'NP': ['Det N'], 'VP': ['V NP'], 'Det': ['the', 'a'], 'N': ['cat', 'dog'], 'V': ['chased', 'saw']}, 'S') in ['the cat chased the dog', 'the cat chased a dog', 'the cat saw the dog', 'the cat saw a dog', 'the dog chased the cat', 'the dog chased a cat', 'the dog saw the cat', 'the dog saw a cat', 'a cat chased the dog', 'a cat chased a dog', 'a cat saw the dog', 'a cat saw a dog', 'a dog chased the cat', 'a dog chased a cat', 'a dog saw the cat', 'a dog saw a cat']
  assert generate_text({'S': ['A B', 'A C'], 'A': ['alpha'], 'B': ['bravo'], 'C': ['charlie']}, 'S') in ['alpha bravo', 'alpha charlie']
output: import random
  
  def generate_text(grammar, start_symbol):
      def expand(symbol):
          if symbol not in grammar:
              return symbol
          rule = random.choice(grammar[symbol])
          return ' '.join(expand(s) for s in rule.split())
      
      return expand(start_symbol)