Last active
August 29, 2015 14:02
-
-
Save Lysander/40fda01bf98a98432217 to your computer and use it in GitHub Desktop.
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
b@d,c,a | |
a@a,c,e | |
b@b,c,d |
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
;; | |
;; Übler Einzeilerhack | |
;; | |
(require '[clojure.string :as string]) (println (string/join "\n" (map #(let [key (get % 0) value (get % 1)] (string/join "@" [key (string/join "," (sort (string/split value #",")))])) (map #(string/split % #"@") (sort (line-seq (java.io.BufferedReader. *in*))))))) |
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
#!/usr/bin/env python | |
# | |
# Lösung zur Frage in diesem Thread: | |
# http://forum.ubuntuusers.de/topic/sort-doppelt-sortieren/ | |
# | |
import sys | |
def parse(filename): | |
with open(filename) as f: | |
return [(k, v.split(",")) for k, v in (line.strip().split("@") for line in f)] | |
def sorted_data(data): | |
for item in sorted(data, key=lambda item: item[0]): | |
yield (item[0], sorted(item[1])) | |
def dump(data): | |
print("\n".join("{}@{}".format(item[0], ",".join(item[1])) for item in data)) | |
if __name__ == "__main__": | |
dump(sorted_data(parse(sys.argv[1]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment