Skip to content

Instantly share code, notes, and snippets.

@sing1ee
Created July 11, 2012 02:26
Show Gist options
  • Save sing1ee/3087549 to your computer and use it in GitHub Desktop.
Save sing1ee/3087549 to your computer and use it in GitHub Desktop.
put odd before even
# !/usr/bin/python
# -*- encoding: utf-8 -*-
array = [1, 2, 3, 4 ,5 ,6, 7, 8, 9]
odd_pos = 0
for index in range(len(array)):
if array[index] & 1 == 1:
array[odd_pos], array[index] = array[index], array[odd_pos]
odd_pos += 1
print array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment