Sunday 19 November 2017

python - Finding index of characters in a string

def indexes(word, letter):

acc=[]
for i in word:
for g in letter:
if g in
i:
acc.append(word.index(i))
return
acc


if i call the
function indexes("mississippi","s") the following is
returned:



[2, 2, 2,
2]


So, the function
returns the correct amount of letters, but it only returns the first index of where
"s" is found and fills the list with that index. Any reason why
the list doesn't return the index of each
"s"?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...