I do not understand why I am gettin a list instead of a string

I do not understand why I am getting ['!',...'P'] instead of a str

def reverse(text):
new = []
num = []
test = len(text)
for i in range(test):
tot = sorted(new, reverse=True)
for j in tot:
h = str(num)
toto = ''.join(h)
return toto


Try refreshing the lesson. Also h = str(num) seems a little extra as num is already a list of strings. Just the ''.join() is enough. That's just my opinion.


The problem is that toto becomes the string of your list num.
toto=''.join(num) will work.
Try the following:


after h=str(num)
you will see, that the list a will contain a single string and an integer: "['!', 'n', 'o', 'h', 't', 'y', 'P']", 1. So h is not a list of strings, but a string which looks like a list, but num is the list.
So at the end you get toto as a joint string but your input (h) is already a string.
I hope you get what I'm trying to say.

Greetings Kiluah


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