Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Python
I have to just use this list I cant create any list
For example:
a=[5,9,1,1,10,21,34,21,1,3,4,39,40,50,60,70]
Output of this list has to be:
[70, 60, 50, 40, 10, 39, 34, 4, 3, 1, 21, 21, 1, 1, 9, 5]
 
my code:
 
a=[5,9,1,1,10,21,34,21,1,3,4,39,40,50,60,70,3,1]
 
v=len(a)-1
i=0
 
while(i<len(a)):>
      
      d =a[i]%2
      if (d==1):
          if(v<i):>
              print(a)
              break
          l=a[i]
          
          a[i]=a[v]
          a[v]=l
          
          v-=1
          
      i+=1
      
 
if I add any odd number end of the list something went wrong
if ı have this list:
a=[5,9,1,1,10,21,34,21,1,3,4,39,40,50,60,70,3,1]
I got :
[1, 3, 70, 60, 10, 50, 34, 40, 39, 4, 3, 1, 21, 21, 1, 1, 9, 5]
What do I need to do?
Posted 7-May-13 12:32pm
Edited 7-May-13 12:37pm
v2
Comments
richcb at 7-May-13 17:36pm
   
Why did you repost this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 Sergey Alexandrovich Kryukov 195
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 7 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100