summaryrefslogtreecommitdiff
path: root/pypers/marelli/modulo2/sort_ci.py
diff options
context:
space:
mode:
Diffstat (limited to 'pypers/marelli/modulo2/sort_ci.py')
-rwxr-xr-xpypers/marelli/modulo2/sort_ci.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/pypers/marelli/modulo2/sort_ci.py b/pypers/marelli/modulo2/sort_ci.py
new file mode 100755
index 0000000..8751ea5
--- /dev/null
+++ b/pypers/marelli/modulo2/sort_ci.py
@@ -0,0 +1,25 @@
+
+from operator import attrgetter
+
+class CI_name(object):
+ def __init__(self, name):
+ self.name = name
+ self.ci_name = name.lower()
+
+def sorted_ci(iterable):
+ ls = map(CI_name, iterable)
+ ls.sort(key=attrgetter("ci_name"))
+ return [el.name for el in ls]
+
+## second implementation:
+
+def sorted_ci(iterable):
+ ls = [(name.lower(), name) for name in iterable]
+ ls.sort()
+ return [el[1] for el in ls]
+
+if __name__ == "__main__": # test
+ ls = "ciao Nina come Va?".split()
+ print sorted(ls)
+ print sorted_ci(ls)
+