ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change
on this file since 4c930a2 was
b699768,
checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago
|
Initial commit of the refactored SasCalc? module.
|
-
Property mode set to
100644
|
File size:
740 bytes
|
Line | |
---|
1 | # |
---|
2 | |
---|
3 | def uniquelist(inputlist, hash=None): |
---|
4 | '''remove redunduant elements from the give list |
---|
5 | and return a list of unique elements. |
---|
6 | |
---|
7 | inputlist: input list |
---|
8 | hash: use this function to make the items in the list hashable. |
---|
9 | |
---|
10 | Implementation details: |
---|
11 | This function is order-preserving. |
---|
12 | ''' |
---|
13 | if hash is None: |
---|
14 | hash = __builtins__.hash |
---|
15 | seen = {} |
---|
16 | result = [] |
---|
17 | for item in inputlist: |
---|
18 | marker = hash(item) |
---|
19 | if marker in seen: continue |
---|
20 | seen[marker] = 1 |
---|
21 | result.append(item) |
---|
22 | return result |
---|
23 | |
---|
24 | |
---|
25 | def test(): |
---|
26 | assert uniquelist([1,2,2,3])==[1,2,3] |
---|
27 | return |
---|
28 | |
---|
29 | |
---|
30 | def main(): |
---|
31 | test() |
---|
32 | return |
---|
33 | |
---|
34 | if __name__ == '__main__': main() |
---|
35 | |
---|
36 | |
---|
37 | # version |
---|
38 | __id__ = "$Id$" |
---|
39 | |
---|
40 | # End of file |
---|
Note: See
TracBrowser
for help on using the repository browser.