Your task is to remove all duplicate words from a string, leaving only single (first) words entries.

Example:

Input:

'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'

Output:

'alpha beta gamma delta'

Source: codewars | Difficulty: EASY
Tags: String algorithms

Starter code: def remove_duplicate_words(s):
	

Solutions:
def remove_duplicate_words(s):
	return ' '.join(dict.fromkeys(s.split()))


def remove_duplicate_words(s):
	s = s.split(' ')
	words = []
	for item in s:
		if item not in words:
			words.append(item)
	return ' '.join(words)


def remove_duplicate_words(s):
	return ' '.join(sorted(set(s.split()), key=s.index))


def remove_duplicate_words(s):
	a = []
	[a.append(v) for v in s.split(' ') if v not in a]
	return str(' ').join(a)


def remove_duplicate_words(s):

	def f():
		seen = set()
		for word in s.split():
			if word in seen:
				continue
			seen.add(word)
			yield word
	return ' '.join(f())


from collections import OrderedDict
remove_duplicate_words = lambda s: ' '.join(OrderedDict.fromkeys(s.split(' ')))


def remove_duplicate_words(s):
	new_list = []
	for word in s.split():
		if word not in new_list:
			new_list.append(word)
	return ' '.join(new_list)


d = {}
remove_duplicate_words = lambda s: ' '.join((d.setdefault(w, w) for w in s.split() if w not in d))


remove_duplicate_words = lambda s: (lambda x: ' '.join((e for (i, e) in enumerate(x) if e not in x[:i])))(s.split())


def remove_duplicate_words(s):
	return ' '.join({i: 0 for i in s.split()})


def remove_duplicate_words(s):
	res = {}
	for (i, n) in enumerate(s.split()):
		if n not in res:
			res[n] = i
	return ' '.join(sorted(res, key=res.get))


def remove_duplicate_words(s):
	return ' '.join((s.split()[i] for i in range(len(s.split())) if s.split()[i] not in s.split()[0:i]))


def remove_duplicate_words(s):
	seen = set()
	result = []
	for word in list(s.split(' ')):
		if word not in seen:
			seen.add(word)
			result.append(word)
	return ' '.join(result)


def remove_duplicate_words(s):
	l = s.split()
	words = []
	for elt in l:
		if elt not in words:
			words.append(elt)
	return ' '.join(words)


def remove_duplicate_words(s):
	final = []
	for s in s.split():
		if s not in final:
			final.append(s)
	return ' '.join(final)


def remove_duplicate_words(s):
	tot = []
	for i in s.split():
		if i not in tot:
			tot.append(i)
	return ' '.join(tot)
	return ' '.join(tot)


from functools import reduce

def remove_duplicate_words(s):
	return ' '.join(reduce(lambda l, x: l + [x] if x not in l else l, s.split(' '), []))


def remove_duplicate_words(s):
	arr = s.split()
	arr1 = []
	for el in arr:
		if not el in arr1:
			arr1.append(el)
	return ' '.join(arr1)


def remove_duplicate_words(s):
	ss = list(set(s.split()))
	ss.sort(key=s.index)
	return ' '.join(ss)


def remove_duplicate_words(s):
	o = []
	x = s.split()
	for y in x:
		if y not in o:
			o.append(y)
	return ' '.join(o)


def remove_duplicate_words(s):
	result = []
	[result.append(w) for w in s.split(' ') if not w in result]
	return ' '.join([x for x in result])


remove_duplicate_words = lambda s: ' '.join(dict.fromkeys(s.split()))


def remove_duplicate_words(s):
	array = s.split()
	output = []
	for word in array:
		if word not in output:
			output.append(word)
	return ' '.join(output)


def remove_duplicate_words(s):
	my_set = []
	for word in s.split(' '):
		try:
			my_set.index(word)
		except ValueError:
			my_set.append(word)
	return ' '.join(my_set)


def remove_duplicate_words(s):
	already = []
	for i in s.split():
		if i in already:
			continue
		if i not in already:
			already.append(i)
	return ' '.join(already)


def remove_duplicate_words(s):
	d = s.split()
	d = list(dict.fromkeys(d))
	print(d)
	anwser = ' '.join(d)
	return anwser


from functools import reduce

def remove_duplicate_words(s):
	return reduce(lambda res, curr: res if curr in res else res + ' ' + curr, s.split(), '').lstrip()


def remove_duplicate_words(s):
	removed = s.split()
	newlist = []
	for i in removed:
		if i not in newlist:
			newlist.append(i)
	newstring = ' '.join(newlist)
	return newstring


def remove_duplicate_words(s):
	arr = s.split()
	new = []
	for i in arr:
		if i not in new:
			new.append(i)
	return ' '.join(new)


def remove_duplicate_words(s):
	arr = s.split()
	res_list = []
	for elem in arr:
		if not elem in res_list:
			res_list.append(elem)
	return ' '.join(res_list)


def remove_duplicate_words(s):
	l = []
	for i in s.split():
		if not i in l:
			l.append(i)
		else:
			pass
	return ' '.join(l)


def remove_duplicate_words(s):
	split = s.split(' ')
	end = []
	for word in split:
		if word in end:
			continue
		end.append(word)
	return ' '.join(end)


def remove_duplicate_words(s):
	single = []
	for x in s.split():
		if x not in single:
			single.append(x)
	return ' '.join(single)


def remove_duplicate_words(s):
	lst = s.split()
	lst_new = []
	for i in lst:
		if i not in lst_new:
			lst_new.append(i)
	return ' '.join(lst_new)


def remove_duplicate_words(s):
	s_list = s.split()
	result_list = []
	for word in s_list:
		if word not in result_list:
			result_list.append(word)
	return ' '.join(result_list)


def remove_duplicate_words(s):
	cadena = s.split()
	cadena2 = []
	cadena3 = ' '
	for i in cadena:
		if i in cadena2:
			pass
		else:
			cadena2.append(i)
	cadena3 = cadena3.join(cadena2)
	return cadena3


def remove_duplicate_words(s):
	new = ''
	sSplit = s.split(' ')
	print(sSplit)
	for i in sSplit:
		if i not in new:
			new += i + ' '
	return new.rstrip()


def remove_duplicate_words(s):
	s = s.split(' ')
	a = ''
	for x in range(len(s)):
		if s[x] not in a:
			a += s[x] + ' '
	return a[:-1]


def remove_duplicate_words(s):
	x = [s for s in s.split()]
	ans = []
	for y in x:
		if y not in ans:
			ans.append(y)
	return ''.join((x + ' ' for x in ans))[:-1]


def remove_duplicate_words(s):
	list_of_words = s.split()
	compressed = []
	for word in list_of_words:
		if word not in compressed:
			compressed.append(word)
		else:
			pass
	compressed_to_string = ' '.join(compressed)
	return compressed_to_string


def remove_duplicate_words(sentence):
	lst = [sentence][0].split()
	no_dbls = list(dict.fromkeys(lst))
	return ' '.join(no_dbls)


def remove_duplicate_words(x):
	y = []
	for i in x.split():
		if i in y:
			pass
		else:
			y.append(i)
	return ' '.join(y)


def remove_duplicate_words(s):
	no_dup = []
	no_dup1 = []
	for c in s.split(' '):
		if c not in no_dup:
			no_dup.append(c)
		else:
			no_dup1.append(c)
	return ' '.join(no_dup)


def remove_duplicate_words(s):
	return ' '.join((i for (loop, i) in enumerate(s.split()) if s.split().index(i) == loop))


def remove_duplicate_words(s):
	words = s.split()
	new_list = []
	for i in words:
		if i not in new_list:
			new_list.append(i)
	new_list = ' '.join(new_list)
	return new_list


def remove_duplicate_words(s):
	return ' '.join(list({x: 1 for x in s.split(' ')}))


def remove_duplicate_words(s):
	seperated = s.split()
	mylist = list(dict.fromkeys(seperated))
	return ' '.join(mylist)


from collections import Counter

def remove_duplicate_words(strr):
	input = strr.split(' ')
	for i in range(0, len(input)):
		input[i] = ''.join(input[i])
	UniqW = Counter(input)
	s = ' '.join(UniqW.keys())
	return s


def remove_duplicate_words(s):
	words = set()
	stree = ''
	for word in s.split():
		if word not in words:
			stree += word + ' '
			words.add(word)
	return stree[0:-1]


def remove_duplicate_words(s):
	seen = set()
	words = []
	for word in s.split(' '):
		if word not in seen:
			seen.add(word)
			words.append(word)
	return ' '.join(words)


def remove_duplicate_words(s):
	result = []
	s = s.split(' ')
	for (i, word) in enumerate(s):
		if word not in result:
			result.append(word)
		else:
			pass
	return ' '.join(result)


def remove_duplicate_words(str):
	l = str.split()
	s = []
	r = []
	for i in range(len(l)):
		if l[i] not in s:
			s.append(l[i])
			r.append(l[i])
	satr = ' '.join([elem for elem in r])
	return satr


from collections import OrderedDict
from collections import Counter

def remove_duplicate_words(s):
	s = s.split(' ')
	s = OrderedDict.fromkeys(s)
	return ' '.join(s)


from collections import OrderedDict

def remove_duplicate_words(s):
	spliter = s.split()
	return ' '.join(OrderedDict.fromkeys(spliter))


def remove_duplicate_words(s):
	d = dict(((i, s.split(' ').count(i)) for i in s.split(' ')))
	return ' '.join(d.keys())


def remove_duplicate_words(s):
	res = []
	s = s.split()
	visited = set()
	for w in s:
		if w not in visited:
			res.append(w)
			visited.add(w)
	return ' '.join(res)


def remove_duplicate_words(s):
	list = s.split()
	new = []
	for x in list:
		if x not in new and new.count(x) == 0:
			new.append(x)
	s = ' '
	return s.join(new)


def remove_duplicate_words(s):
	D = []
	words = s.split(' ')
	for word in words:
		if word not in D:
			D.append(word)
		else:
			pass
	return ' '.join(D)


import re

def remove_duplicate_words(s):
	s_list = []
	s_2 = ''
	all = s.split()
	for word in s.split():
		if word not in s_list:
			s_2 += ' ' + word
			s_list.append(word)
	return s_2.strip()


def remove_duplicate_words(s):
	q = ''
	a = s.split(' ')
	for i in a:
		if i not in q:
			q += i + ' '
	return q[:-1]


from collections import Counter

def remove_duplicate_words(s):
	new = []
	for i in Counter(s.split(' ')):
		new.append(i)
	return ' '.join(new)


import re

def remove_duplicate_words(s):
	sx = []
	for i in s.split():
		if i not in sx:
			sx.append(i)
	return ' '.join(sx)


def remove_duplicate_words(s):
	split_string = s.split()
	new_string = ''
	for word in split_string:
		if word not in new_string:
			new_string += word + ' '
		else:
			continue
	return new_string.rstrip()


def remove_duplicate_words(s):
	t = set()
	s = s.split()
	r = []
	for w in s:
		if w not in t:
			t.add(w)
			r.append(w)
	return ' '.join(r)


def remove_duplicate_words(s):
	list = s.split()
	index = 0
	empty = []
	while index < len(list):
		if list[index] not in list[0:index]:
			empty.append(list[index])
		index += 1
	return ' '.join(empty)


def remove_duplicate_words(s):
	no_dup = set()
	lstt = []
	for i in s.split():
		print(i)
		if i not in lstt:
			lstt.append(i)
		f = ' '.join(lstt)
	return f


def remove_duplicate_words(s):
	a = []
	c = s.split(' ')
	for i in c:
		if i not in a:
			a.append(i)
	return ' '.join(a)


def remove_duplicate_words(x):
	a = ''
	for i in x.split():
		if i not in a:
			a += i + ' '
	return a[:-1]


def remove_duplicate_words(s):
	nwrd = []
	for i in s.split(' '):
		if i in nwrd:
			pass
		else:
			nwrd.append(i)
	return ' '.join(nwrd)


def remove_duplicate_words(s):
	res = []
	s = s.split(' ')
	for w in s:
		if w not in res:
			res.append(w)
	erg = ''
	for r in res:
		erg += r + ' '
	return erg[:-1]


def remove_duplicate_words(string):
	string = string.split(' ')
	lst = []
	for word in string:
		if word not in lst:
			lst.append(word)
	return ' '.join(lst)


def remove_duplicate_words(s):
	res = ''
	k = s.split()
	for i in k:
		if i not in res:
			res += i + ' '
	return res.rstrip()


import re

def remove_duplicate_words(s):
	result = []
	s_l = s.split(' ')
	for x in s_l:
		if x not in result:
			result.append(x)
	result = ' '.join(result)
	return result


from collections import OrderedDict

def remove_duplicate_words(s):
	a = s.split(' ')
	return ' '.join(list(OrderedDict.fromkeys(a)))


from collections import OrderedDict

def remove_duplicate_words(s):
	return ' '.join(OrderedDict(((x, None) for x in s.split())).keys())


def remove_duplicate_words(s):
	return ' '.join(list({i: True for i in s.split(' ')}))


def remove_duplicate_words(str):
	return ' '.join(sorted(set(str.split()), key=str.split().index))