def first_non_repeating_char(string): char_count = {} # Count the occurrences of each character in the string for char in string: char_count[char] = char_count.get(char, 0) + 1 # Find the first character with count 1 for char in string: if char_count[char] == 1: return char return Noneinput_string = "aaAbbccddeeffK"result = first_non_repeating_char(input_string)print("First non-repeating character:", result) # Output: A
def first_non_repeating_char(string):
char_count = {}
# Count the occurrences of each character in the string
for char in string:
char_count[char] = char_count.get(char, 0) + 1
# Find the first character with count 1
if char_count[char] == 1:
return char
return None
input_string = "aaAbbccddeeffK"
result = first_non_repeating_char(input_string)
print("First non-repeating character:", result) # Output: A
please find below solution`string = “hello”index = -1fnc = “”
if len(string) == 0 : print(“EMTPY STRING”);
for i in string: if string.count(i) == 1: fnc += i break else: index += 1if index == len(string)-1 : print(“All characters are repeating “)else: print(“First non-repeating character is”, fnc)`
def first_non_repeating_character(input_string):char_count = {}# Count the occurrences of each character in the stringfor char in input_string:char_count[char] = char_count.get(char, 0) 1# Find the first non-repeating characterfor char in input_string:if char_count[char] == 1:return char# If every character repeats, return Nonereturn None# Example usage: input_str = "abacabad" result = first_non_repeating_character(input_str)if result is not None:print(f"The first non-repeating character is: {result}") else:print("Every character repeats.")