Yasoda went to a store to buy Ingredients to make a boul of soup.While billing the order,salesperson found that some ingredients are stale.So, he wants to separate the stale ingredients from the rest.You are given the prices of the ingredients,where a negative price value indicates a stale ingredient.Write a program to help the sales person to move the prices of all the stale ingredients to left without changing the relative order of the ingredients.
Input
The first line of input contains space-separated integers.
Explanation
In the example, there are 6 ingredients with prices 11,-12,13,-14,15,16 respectively.
The prices of the stale ingredients in the given list are -12 and -14 in the order of occurence.
So, the output is -12 -14 11 13 15 16.
Sample Input1
11 -12 13 -14 15 16
Sample Output1
-12 -14 11 13 15 16
Sample Input2
21 11 -3 -2 9
Sample Output2
-3 -2 21 11 9
price = input("Enter price separated by a space: ").split(' ')
price = [int(i) for i in price]
print("You entered: " + str(price))
stale_ingredients = []
fresh_ingredients = []
for i in range(len(price)):
if price[i] > 0:
fresh_ingredients.append(price[i])
else:
stale_ingredients.append(price[i])
result = stale_ingredients + fresh_ingredients
print("Result: " + str(result))
Comments
Leave a comment