Write a Python program to find the first non-repeating character in given string


This program is finding the unique characters in a string "Tutor Joes". The program first initializes two empty lists, char_order and ctr. char_order is used to store the order of characters in the string, and ctr is a dictionary used to store the count of each character in the string.

The program then uses a for loop to iterate through each character in the string. For each character, the program checks if the character is already in the ctr dictionary. If the character is already in the ctr dictionary, its count is incremented by 1. If the character is not in the ctr dictionary, it is added as a key with a value of 1 and also added to the char_order list.

After the for loop, another for loop is used to iterate through each character in the char_order list. For each character, the program checks if its count in the ctr dictionary is 1. If its count is 1, it means that the character is unique in the string, and it is printed to the console using the print function.

Source Code

str1="Tutor Joes"
char_order = []
ctr = {}
for c in str1:
	if c in ctr:
	  ctr[c] += 1
	else:
	  ctr[c] = 1 
	  char_order.append(c)
for c in char_order:
	if ctr[c] == 1:
	  print(c)

Output

T
u
t
r

J
e
s


Example Programs