111k views
2 votes
Write a function "nonRepeatings" that takes a string "s3" and returns the non-repeating characters in this string. Sample Input s3 = "aaazzzdcccrttt" Sample Output The non-repeating characters are; d ryou are suppose to use for loops to go throw and return a dictionary of non repeating letters.

User Finslicer
by
4.4k points

1 Answer

7 votes

Answer:

def nonRepeatings(s3):

non = []

letter_dictionary = {}

for l in s3:

if l in letter_dictionary:

letter_dictionary[l] += 1

else:

letter_dictionary[l] = 1

for c in letter_dictionary:

if letter_dictionary[c] == 1:

non.append(c)

return non

Step-by-step explanation:

- Declare an empty list and a dictionary

- Initialize a for loop that iterates through the given string s3

Inside the loop:

- If a character in the string is in the dictionary, increment its count by 1. If not, add it to the dictionary

When the first loop is done, initialize another for loop that iterates through the dictionary.

- Inside the loop, check if any character has a value of 1, put it to the non.

- Finally, return the non

User Paul Williams
by
4.7k points