source: sasview/src/sas/data_util/uniquelist.py @ ae2a197

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ae2a197 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 740 bytes
Line 
1#
2
3def 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
25def test():
26    assert uniquelist([1,2,2,3])==[1,2,3]
27    return
28
29
30def main():
31    test()
32    return
33
34if __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.