WAP to display +ve elements of an array first then all negative without altering the
original sequence
For example
If an array contains
: 2,3,-5, 22, -8,5, 77,-88, 3,-9, 45, -23, -2
The output will be
: 2,3, 22, 5, 77,3, 45, -5, -8, -88,-9, -23, -2
Answers
Answered by
1
from array import array
arr = array("i", [2, 3, -5, 22, -8,5, 77, -88, 3, -9, 45, -23, -2])
pos, neg = [n for n in arr if n > 0], [n for n in arr if n < 0]
print(array("i", [*pos, *neg]))
Similar questions