What I'm trying to do is to print the reverse number of the input. input = "1 3 4 2" output = "2 4 3 1"
I want to know why my code show this error:
if __name__ == "__main__":
n = 4
arr = map(int, "1 3 4 2".split())
ar = list(arr)
ar.reverse()
string = ' '
string.join(ar)
print(string)
Error:
string.join(ar)
TypeError: sequence item 0: expected str instance, int found
and if i change the map argument from int to str, it shows no result.
map(intpart and it should work.list(map()), eh. It also looks like you’re not saving the result of yourjoinanywhere.arr = map(int, "1 3 4 2".split())the "1 3 4 2" should be the input with that format. I simplified the code and tried to understand python. that's why i need the map() and turn it into a list.