Commit 94384154 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Ability to sort cam sets in alphabetical order

parent b3a7b7d7
# -*- coding: utf-8 -*-
def sort_solutions(file):
"""Sort all solutions in alphabetical order in place."""
solutions = dict()
with open(file, 'r+') as fd:
for line in fd:
line = line.rstrip('\n')
# Remove possible \t separator from first line (frontier solution)
stripped_line = line.rstrip('\t').replace('\t', ' ')
if stripped_line[0] not in ('%', '=', ' ', ''):
# print(stripped_line)
# Sort in lower case, remove ' ' empty elements
solutions[line] = \
" ".join(sorted([place for place in stripped_line.split(' ') if place != ' '], key=lambda s: s.lower()))
# Rewind
fd.seek(0)
# Load all the content
file_text = fd.read()
# Replace old sols with the new
for original_sol, sorted_sol in solutions.items():
file_text = file_text.replace(original_sol, sorted_sol)
# print(file_text)
# Rewind
fd.seek(0)
# Write all text in place
fd.write(file_text)
if __name__ == "__main__":
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment