input: Write a python function to count the number of common characters in two strings.
  assert num_common_substrings("abcd", "bae") == 2
  assert num_common_substrings("hello", "world") == 2
  assert num_common_substrings("python", "java") == 1
output: def num_common_substrings(str1, str2):
      set1 = set(str1)
      set2 = set(str2)
      common_characters = set1.intersection(set2)
      return len(common_characters)