Jul-20-2017, 05:10 PM
my question here
Define a function that takes an array of numbers and sorts only the odd ones in ascending order, leaving the even ones in their places. No need to move the number 0 should it occur. Here is an example:
sort_odds([1,5,3,2,7,7,3,2,7]) -> [1, 3, 3, 2, 5, 7, 7, 2, 7]
How can I add the even # back to their original positions?
[
python]my code here[/python]
def sort_odds(arr):
return sorted([i for i in arr if i%2!= 0])
Define a function that takes an array of numbers and sorts only the odd ones in ascending order, leaving the even ones in their places. No need to move the number 0 should it occur. Here is an example:
sort_odds([1,5,3,2,7,7,3,2,7]) -> [1, 3, 3, 2, 5, 7, 7, 2, 7]
How can I add the even # back to their original positions?
[
python]my code here[/python]
def sort_odds(arr):
return sorted([i for i in arr if i%2!= 0])