Reverse


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096#

I tried every thing I can think of but it skill turns out Oops, try again. Your function fails on reverse("coolstory"). It returns "yroootslc" when it should return "yrotslooc". please help


def reverse(text):
    list1 = list(text)
    list2 = list();
    
    while len(list1) > 0:
        n = len(list1)
        x = n - 1
        list2.append(list1[x])
        list1.remove(list1[x])
    
    return "".join(list2)


#2

remove removes based on matching items:

example = ['a','b','c']
example.remove('a')

use del to delete based on index (x contains indexes):

del example[0]

#3

thanks that really helped me


#4

issue resolved?


#5

How about this?

def reverse (text):
    from string import join
    list = []
    for char in text:
       list.insert(0, char)
    return ''.join (list)

#6

works fine, what is your question? You don't have to import join, it is imported by default


#7

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