Skip to content

Instantly share code, notes, and snippets.

@Maslor
Last active March 16, 2016 18:24
Show Gist options
  • Save Maslor/29d208e9727f855710e1 to your computer and use it in GitHub Desktop.
Save Maslor/29d208e9727f855710e1 to your computer and use it in GitHub Desktop.
Breaks down a string an iterates its characters.
def detectSpecificChars():
key = "masterkey"
string = raw_input ("Insirt a string: ")
if string == key:
return None
letterArray = []
positionArray = []
for letter in string:
letterArray = letterArray + [letter]
for i in range(len(letterArray) - 1):
if letterArray[i] == "a":
positionArray = positionArray + [i]
'''
A mesma coisa que o loop anterior, mas itera os valores em vez dos indices.
for element in letterArray:
if element == "a":
return "Contem uma letra 'A'" '''
return "Letra 'A' na posicao: \n" + str(positionArray)
while True:
displayString = detectSpecificChars()
if displayString != "" and displayString != None:
print(displayString)
else:
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment