Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
94384154
Commit
94384154
authored
Jan 23, 2017
by
VIGNET Pierre
Browse files
Ability to sort cam sets in alphabetical order
parent
b3a7b7d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
solution_sort.py
0 → 100644
View file @
94384154
# -*- 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment