Skip to content

Instantly share code, notes, and snippets.

@Lysander
Last active August 29, 2015 14:02
Show Gist options
  • Save Lysander/40fda01bf98a98432217 to your computer and use it in GitHub Desktop.
Save Lysander/40fda01bf98a98432217 to your computer and use it in GitHub Desktop.
b@d,c,a
a@a,c,e
b@b,c,d
;;
;; Ü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*)))))))
#!/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