human
Can you provide a code to remove duplicates from string keeping the order according to last occurrences and the other steps required given the following:
Remove duplicates from string keeping the order according to last occurrences | Python3 program to remove duplicate character from character array and prin sorted order.
Used as index in the modified string.
Create an empty hash table.
Traverse through all characters from right to left.
If current character is not in.
Reverse the result string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to remove duplicates from string keeping the order according to last occurrences and the other steps required.
 def removeDuplicates ( str ) :
	n = len ( str )
	s = set ( )
	res = " "
	for i in range ( n - 1 , - 1 , - 1 ) :
		if ( str [ i ] not in s ) :
			res = res + str [ i ]
			s . add ( str [ i ] )
	res = res [ : : - 1 ]
	return res
str = " geeksforgeeks "
print ( removeDuplicates ( str ) )