I'm new to python and am getting an error with the map function that doesn't make sense to me. When I call the function with a list as the second parameter it returns the error 'TypeError: Argument 2 must support iteration' which confuses me because a list should support iteration.
import numpy as np
print(np.array(map(int, raw_input().split().reverse()), float))
The code is meant to take in a list, and print out a numpy that is the reverse of the list. Any help as to why the second paramter isn't iteratable would be appreciated. Thanks!
list.reverse()
function reverses the list in-place and returns None
. If you want to write this as one line you may write reversed(raw_input().split())
instead.
.reverse()
does the reverse in-place and returns None
.
Get rid of the .reverse()
and call reversed()
instead like so, which should fix your issue:
import numpy as np
print(np.array(map(int, reversed(raw_input().split())), float))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With