+ 2
How to sort only the odd numbers in an list
Help me with this question So if you have a list like[3,5,4,2,6,9,1,7] Then you should return like [1,3,5,4,2,6,7,9].
6 Answers
+ 1
Problem Solved
https://code.sololearn.com/cwVhIMCdmwqP/?ref=app
+ 1
Yes they will be.
X =[3,5,4,2,6,9,1,7]
Even=[ i for i in X if i%2==0]
Odd =[i for i in X if i%2!=0]
Even.sort()
Odd.sort()
Print(Even+Odd)
This is just the example.Might have little errors.But you get the idea.
X=[1,3]
Y=[2,4]
Print(x+y) >>>>> [1,3,2,4]
+ 1
I am thinking so you are not getting me . So if you have [1,3,2,6, 7,4,5] I want to get the output as [1,3,2,6,5,4,7].
+ 1
No. only the odd numbers are sorted and even remains in the same position.
- 1
You can split a list in 2. One containing odd other is Even.
Then sort both list and merge them.