Skip to content

Instantly share code, notes, and snippets.

@matdombrock
Created September 9, 2017 06:48
Show Gist options
  • Save matdombrock/90e5ec6b3899851ec9f6cbdecee72433 to your computer and use it in GitHub Desktop.
Save matdombrock/90e5ec6b3899851ec9f6cbdecee72433 to your computer and use it in GitHub Desktop.
Python Change Order of Lines
import os
for filename in os.listdir("."):
if(filename != "re.py"):
with open(filename, "r") as infile:
lines = [line for line in infile] # Read all input lines into a list
ordering = [0,1,2,3,4,5,6,7]#change this
with open(filename, "w") as outfile:
for idx in ordering: # Write output lines in the desired order.
outfile.write(lines[idx])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment