0

I am trying to return the first letter that is a duplicate within a string. I am able to do it with the print method but always get none if I try to return the string.

This code works:

def recurringLetter(word):
    if word[0] == word[1]:
        print(word[0])
    elif len(word) == 0:
        print("None")
    else:
        recurringLetter(word[1:])

string = input()
recurringLetter(string)

But this code always returns none:

def recurringLetter(word):
    if word[0] == word[1]:
        return word[0]
    elif len(word) == 0:
        return None
    else:
        recurringLetter(word[1:])

string = input()
recurringLetter(string)
Nick
  • 138,499
  • 22
  • 57
  • 95

0 Answers0