How does it know it is unique

Hello me again,

I was working on the count letter problem here.

letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
# Write your unique_english_letters function here:
def unique_english_letters(word):
  uniques = 0
  for letter in letters:
    if letter in word:
      uniques += 1
  return uniques

Thats the code that works but I don’t understand why the code wouldn’t count repeated letters.

For example if you run:

print(unique_english_letters("mississippi"))
>>> 4

When it checks the first ‘s’ the count should go up as planned, but when it checks the second ‘s’ why wouldn’t it up the count since ‘s’ is still part of the original list letters.

Thank you

1 Like

you have the letters variable:

letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

this is what you are looping over, you are not looping over word variable (which in this case is "mississippi".

by looping over letters, you can check for each letter if its in word

3 Likes