summaryrefslogtreecommitdiff
path: root/pypers/marelli/modulo2/sort_ci.py
blob: 8751ea585a2ba71338941bef6a2aa89f19d3181d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)