Created
November 5, 2016 16:23
-
-
Save varundey/bc92514c23dd2a8d1e06ff2b1d2221f1 to your computer and use it in GitHub Desktop.
Arranges list in negatives and positives and creates alternate of those numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = map(int, raw_input().split()) | |
def rearrange(li): | |
val = len(li)-1 | |
for i in range(len(li)): | |
if li[i]>0 and i<mid: | |
while True: | |
if li[val]<0: | |
li[i], li[val] = li[val], li[i] | |
break | |
val -=1 | |
return li | |
def alternate(li): | |
count = 0 | |
for i in range(1,len(li),2): | |
li[i], li[len(li)-i] = li[len(li)-i], li[i] | |
count+=1 | |
if count==mid/2: | |
break | |
return li | |
if __name__ == "__main__": | |
mid = len(a)/2 | |
a = rearrange(a) | |
print a | |
a = alternate(a) | |
print a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment