0
I have a question about the "First recurring characters" problem (Python)
I can find a lot of codes that work for this. But the thing that I want to ask about is that if the given string is "ABBA", the codes I get return B because B is the first repeated char, but I want a code that could return A because A is the first char that has repetition. The code I found about this looks complicated and I can't understand it, can someone give me a (Python) code for it with comments for explanations? Much appreciated, thanks.
8 Réponses
+ 2
you could do that like this:
go through the string
at each character test if it's in the rest of the string(everything right of where you are in the String right now)
if there is one, that will be your result
else continue with the next character
+ 2
Airree question duplication happens when your connection isn't that great, it happens to me so often😩
(if you look at the time of the post, you'll see that their posted at the exact same time)
+ 1
Anton Böhler I am aware of that, but the question still can be deleted
+ 1
Thanks everyone
0
Please don't ask the same question twice
I know little about python, but I know that there are regular expressions. I made a javascript code which works, and if you can implement it in python, then good for you, you got yourself an answer.
0
Note: the code will return the first character that has repetition in the string.
A will be returned when string is 'ABBA'
string =list(input())
for i in range(len(string)):
a=string[i]
string.pop(i)
if i==len(string)-1:
print('No recurring characters.')
break
if a in string:
print(a +' is the recurring character.')
break