How to return 1 or -1 if number is positive or negative (including 0)?

Viewed 6517

Can I ask how to achieve this in Python:

Input: I = [10,-22,0]

Output: O = [1,-1,-1]

I was thinking O=I/abs(I)

But how to deal with zero?

2 Answers
Related