Last active
May 29, 2019 01:33
-
-
Save hygull/8fdeb4c28fa0c91a6b7fa09b18af85c0 to your computer and use it in GitHub Desktop.
Python script to find the first repeated character in string created by hygull - https://repl.it/HJ0l/0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
{ | |
"created_on" : "14 April 2017", | |
"aim_of_script" : "Python script to find the first repeated character in string", | |
"coded_by" : "Rishikesh Agrawani", | |
"python_version" : "2.7.12", | |
"special" : "As an alternative to the pyscript available at http://www.geeksforgeeks.org/find-the-first-repeated-character-in-a-string/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+Geeksforgeeks+%28GeeksforGeeks%29" | |
} | |
""" | |
def first_repeated_character( s ): | |
for index,ch in enumerate(s): | |
if s[:index+1].count(ch) > 1: | |
return ch | |
return "\0" | |
#Case1 | |
print first_repeated_character("Geeksforgeeks") #e | |
#Case2 | |
print first_repeated_character("geeksforgeeks") #g | |
#Case3 | |
print first_repeated_character("hello geeks") #l | |
#Case4 | |
print first_repeated_character("FishForFree") #F | |
#Case5 | |
print first_repeated_character("") #NUL | |
#Case6 | |
print first_repeated_character("@@") #@ | |
""" | |
e | |
e | |
l | |
F | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment