For some reason, when I do the code…
def encode():
result2 = []
print result
for x in result:
result2 += str(x)
print result2
I get…
[123, 456, 789]
['1', '2', '3', '4', '5', '6', '7', '8', '9']
How do I get it to return ['123', '456', '789']?
Thanks!
How about:
The reason you are getting what you are getting is the
+=is doing list concatenation. Sincestr(123)is'123', which can be seen as['1', '2', '3'], when you concatenate that to the empty list you get['1', '2', '3'](same thing for the other values).For it to work doing it your way, you’d need: