code: def cluster_doubles(double_list):
      
      location = {}  # hashtable of which cluster each element is in
      clusters = []
      # Go through each double
      for t in double_list:
          a, b = t[0], t[1]
          # If they both are already in different clusters, merge the clusters
          if a in location and b in location:
              if location[a] != location[b]:
                  if location[a] < location[b]:
                      clusters[location[a]] = clusters[location[a]].union(clusters[location[b]])  # Merge clusters
                      clusters = clusters[:location[b]] + clusters[location[b]+1:]
                  else:
                      clusters[location[b]] = clusters[location[b]].union(clusters[location[a]])  # Merge clusters
                      clusters = clusters[:location[a]] + clusters[location[a]+1:]
                  # Rebuild index of locations for each element as they have changed now
                  location = {}
                  for i, cluster in enumerate(clusters):
                      for c in cluster:
                          location[c] = i
          else:
              # If a is already in a cluster, add b to that cluster
              if a in location:
                  clusters[location[a]].add(b)
                  location[b] = location[a]
              # If b is already in a cluster, add a to that cluster
              if b in location:
                  clusters[location[b]].add(a)
                  location[a] = location[b]
              # If neither a nor b is in any cluster, create a new one with a and b
              if not (b in location and a in location):
                  clusters.append(set(t))
                  location[a] = len(clusters) - 1
                  location[b] = len(clusters) - 1
      return map(tuple, clusters)
docs: Given a list of doubles, they are clustered if they share one element
      :param double_list: list of doubles
      :returns : list of clusters (tuples)