Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hygull/8fdeb4c28fa0c91a6b7fa09b18af85c0 to your computer and use it in GitHub Desktop.
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
"""
{
"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