Computer Science, asked by vineeshreddy4, 3 months ago

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 jai696
1

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

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]))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions