Q: Code to output the first repeated character in given string? I'm trying to find the first repeated character in my string and output that character using python. When checking my code, I can see I'm not index the last character of my code.
What am I doing wrong? 
letters = 'acbdc'
for a in range (0,len(letters)-1):
#print(letters[a])
    for b in range(0, len(letters)-1):
        #print(letters[b])
        if (letters[a]==letters[b]) and (a!=b):
            print(b)
            b=b+1
a=a+1


A: You can do this in an easier way:
letters = 'acbdc'
found_dict = {}
for i in letters:
    if i in found_dict:
        print(i)
        break
    else:
        found_dict[i]= 1

Output:
c

A: Here's a solution with sets, it should be slightly faster than using dicts.
letters = 'acbdc'
seen = set()

for letter in letters:
    if letter in seen:
        print(letter)
        break
    else:
        seen.add(letter)


A: Here is a solution that would stop iteration as soon as it finds a dup
>>> from itertools import dropwhile
>>> s=set(); next(dropwhile(lambda c: not (c in s or s.add(c)), letters))
'c'


A: You should use range(0, len(letters)) instead of range(0, len(letters) - 1) because range already stops counting at one less than the designated stop value. Subtracting 1 from the stop value simply makes you skip the last character of letters in this case.
Please read the documentation of range:
https://docs.python.org/3/library/stdtypes.html#range

A: Nice one-liner generator:
l = 'acbdc'
next(e for e in l if l.count(e)>1)

Or following the rules in the comments to fit the "abba" case:
l = 'acbdc'
next(e for c,e in enumerate(l) if l[:c+1].count(e)>1)


A: There were a few issues with your code...
1.Remove -1 from len(letters)
2.Move back one indent and do b = b + 1 even if you don't go into the if statement
3.Indent and do a = a + 1 in the first for loop.
See below of how to fix your code...
    letters = 'acbdc'
    for a in range(0, len(letters)):
        # print(letters[a])
        for b in range(0, len(letters)):
            # print(letters[b])
            if (letters[a] == letters[b]) and (a != b):
                print(b)
            b = b + 1
        a = a + 1


A: If complexity is not an issue then this will work fine.
letters = 'acbdc'
found = False
for i in range(0, len(letters)-1):
    for j in range(i+1, len(letters)):
        if (letters[i] == letters[j]):
            print (letters[j])
            found = True
            break
    if (found):
        break


A: The below code prints the first repeated character in a string. I used the functionality of the list to solve this problem.
      def findChar(inputString): 
          list = []
          for c in inputString:
              if c in list:
                  return c
              else:
                  list.append(c) 
      return 'None'    

      print (findChar('gotgogle'))

Working fine as well. It gives the result as 'g'.

A: 
def first_repeated_char(str1):
    for index,c in enumerate(str1):
      if str1[:index+1].count(c) > 1:
        return c 
    return "None"

print(first_repeated_char("abcdabcd"))



A: str_24 = input("Enter the string:")
for i in range(0,len(str_24)):
    first_repeated_count = str_24.count(str_24[i])
    if(first_repeated_count > 1):
       break
print("First repeated char is:{} and character is 
      {}".format(first_repeated_count,str_24[i]))

