1.

Write a user defined function arrangelements(X),that accepts a list X of integers and sets all the negative elements to the left and all positive elements to the right of the list.Eg: if L =[1,-2,3,4,-5,7] , the output should be: [-2,-5,3,4,7]

Answer»

def arrangelements(X):

L=len(X)

for i in range(L):

if a[i]<0 and i!=0:

j=i

while j!=0 and a[j-1]>0 :

a[j],[j-1]=a[j-1],a[j]

j=j-1



Discussion

No Comment Found

Related InterviewSolutions