code: def chi_squared(source_frequency, target_frequency):
      
      # Ignore any symbols from source that are not in target.
      # TODO: raise Error if source_len is 0?
      target_prob = frequency_to_probability(target_frequency)
      source_len = sum(v for k, v in source_frequency.items() if k in target_frequency)
  
      result = 0
      for symbol, prob in target_prob.items():
          symbol_frequency = source_frequency.get(symbol, 0)  # Frequecy is 0 if it doesnt appear in source
          result += _calculate_chi_squared(symbol_frequency, prob, source_len)
  
      return result
docs: Calculate the Chi Squared statistic by comparing ``source_frequency`` with ``target_frequency``.
  
      Example:
          >>> chi_squared({'a': 2, 'b': 3}, {'a': 1, 'b': 2})
          0.1
  
      Args:
          source_frequency (dict): Frequency map of the text you are analyzing
          target_frequency (dict): Frequency map of the target language to compare with
  
      Returns:
          Decimal value of the chi-squared statistic