7.reverse


#1

def reverse(text):
    text='@'.join(text)
    n=text.split("@")
    m=[]
    for i in n:
        m.insert(i,0)
    text="".join(m)
    return text

I written these code.But the system tell me:
File "python/cli_runner.py", line 152, in

I tried many times.but it tell me some error above.


#2

I do not quite follow what you want to do so I added print commands in your code and fixed errors so please run the below and check line by line if this is what you wanted: (btw in first line left parenthesis is a wrong character )

def reverse(text):  # here left ( is corrected now
    text='@'.join(text)
    print text
    n=text.split("@")
    print n
    m=[]
    for index, i in enumerate(n): # not sure what you wanted here so I added index as .insert
#requires and index - number not a character in first argument
        m.insert(index,'0') # changed 0 to '0' as below .join will not work
    print m
    text="".join(m)
    print text
    return text
    
reverse('What this is about')

#3

two problems, first one is in this line:

def reverse(text):

the ( seems wrong.

then the second problem, insert works slightly different, the first argument is the index you want to place the item, and the second argument is the item, so it should be: insert(0,i)


#4

A post was split to a new topic: 7. reverse