15.7 reverse


#1

This won’t work. Please explain where the error is.

def reverse(s):
  word = []
  for i in range(len(s)):
    word.append(len(s(-i)))
    i -= 1
  word = ' '.join(word)
  return word

#2

Should mention that I had the indents correct, not sure why each line aligned left when I copied the code.


#3

here:

word.append(len(s(-i)))

currently you are appending integers to word, you want to access s by index (to get the letters) to append to the list

to access a string by index we have the following general syntax:

string[index]

isn’t it easier to check documentation on range() function? with 3 arguments, range can loop backwards over a string


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.