input: Write a function to count the number of common substrings between two given strings. The function should take in two strings and return an integer indicating the number of common substrings. If the strings are empty, return 0.
  
  def num_common_substrings(s1, s2):
      count = 0
      for i in range(len(s1)):
          for j in range(len(s2)):
              if s1[i] == s2[j]:
                  count += 1
      return count
  
  assert num_common_substrings("abcd", "bae")==2
  assert num_common_substrings("hello", "world")==1
  assert num_common_substrings("abc", "def")==0
  assert num_common_substrings("", "test")==0
  assert num_common_substrings("test", "")==0
  assert num_common_substrings("", "")==0
output: def num_common_substrings(s1, s2):
      count = 0
      set_s1 = set(s1[i:j] for i in range(len(s1)) for j in range(i + 1, len(s1) + 1))
      set_s2 = set(s2[i:j] for i in range(len(s2)) for j in range(i + 1, len(s2) + 1))
      count = len(set_s1 & set_s2)
      return count