input: Write a python function to generate a random sentence based on a given grammar.
  assert generate_sentence({
      "_S": ["_NP _VP"],
      "_NP": ["I", "you", "she"],
      "_VP": ["love _NP", "hate _NP"]
  }) in ["I love you.", "I love she.", "I hate you.", "I hate she.", "You love I.", "You love she.", "You hate I.", "You hate she.", "She love I.", "She love you.", "She hate I.", "She hate you."]
  assert generate_sentence({
      "_S": ["_NP _VP"],
      "_NP": ["they", "we"],
      "_VP": ["like _NP", "dislike _NP"]
  }) in ["They like we.", "They like they.", "They dislike we.", "They dislike they.", "We like they.", "We like we.", "We dislike they.", "We dislike we."]
output: import random
  
  def generate_sentence(grammar):
      def expand(symbol):
          if symbol not in grammar:
              return symbol
          expansion = random.choice(grammar[symbol]).split()
          return " ".join([expand(s) for s in expansion])
  
      return expand("_S").capitalize() + "."