Given a string, remove any characters that are unique from the string.

Example: 

input: "abccdefee"

output: "cceee"

Difficulty: introductory

Starter code:

def only_duplicates(string):
	

Solutions:
from collections import Counter

def only_duplicates(string):
    cs = Counter(string)
    return ''.join(c for c in string if cs[c] > 1)

def only_duplicates(string):
    return "".join([x for x in string if string.count(x) > 1])

only_duplicates = lambda s: ''.join(c for c in s if s.count(c) > 1)

def only_duplicates(stg):
    return "".join(c for c in stg if stg.count(c) > 1)

def only_duplicates(string):
    return ''.join(s for s in string if string.count(s) > 1)

def only_duplicates(string):
    sets = unique, duplicate = set(), set()
    for c in string: sets[c in unique].add(c)
    return ''.join(c for c in string if c in duplicate)

from collections import Counter

def only_duplicates(string):
    counts = Counter(string)
    return ''.join(c for c in string if counts[c] > 1)

def only_duplicates(a):
    b=[]
    for j in range(0,len(a)):
        for i in range(j+1,len(a)):
            if a[j] == a[i]:
                b.append(a[j])
    #zhao ti shen ye mei you yong
    a=list(a)
    def seclect(i):
            for j in b:
                if j == i:
                    return i

    return ''.join(filter(seclect,a))

def only_duplicates(string):
  string = list(string)
  foundStrings = []
  finalString = []
  
  for index, item in enumerate(string):
    if item not in string[index+1:len(string)] and item not in string[0:index]:
      finalString.append("")
    else:
      finalString.append(item)
          
  return ''.join(finalString)

from collections import Counter
from re import sub


def only_duplicates(s):
    return sub(r"[%s]" % "".join(k for k, v in Counter(s).items() if v == 1), '', s)