code: def collect_loaded_packages() -> List[Tuple[str, str]]:
      
      dists = get_installed_distributions()
      get_dist_files = DistFilesFinder()
      file_table = {}
      for dist in dists:
          for file in get_dist_files(dist):
              file_table[file] = dist
      used_dists = set()
      # we greedily load all values to a list to avoid weird
      # "dictionary changed size during iteration" errors
      for module in list(sys.modules.values()):
          try:
              dist = file_table[module.__file__]
          except (AttributeError, KeyError):
              continue
          used_dists.add(dist)
      return sorted((dist.project_name, dist.version) for dist in used_dists)
docs: Return the currently loaded package names and their versions.