mailr19333 - in /trunk/lib: __init__.py list.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on April 03, 2013 - 16:42:
Author: bugman
Date: Wed Apr  3 16:42:32 2013
New Revision: 19333

URL: http://svn.gna.org/viewcvs/relax?rev=19333&view=rev
Log:
Created the new lib.list module with the function count_unique_elements().

This function will be used to determine the unique number of elements in a 
list.


Added:
    trunk/lib/list.py
Modified:
    trunk/lib/__init__.py

Modified: trunk/lib/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/__init__.py?rev=19333&r1=19332&r2=19333&view=diff
==============================================================================
--- trunk/lib/__init__.py (original)
+++ trunk/lib/__init__.py Wed Apr  3 16:42:32 2013
@@ -37,6 +37,7 @@
     'geometry',
     'io',
     'linear_algebra',
+    'list',
     'model_selection',
     'order',
     'physical_constants',

Added: trunk/lib/list.py
URL: http://svn.gna.org/viewcvs/relax/trunk/lib/list.py?rev=19333&view=auto
==============================================================================
--- trunk/lib/list.py (added)
+++ trunk/lib/list.py Wed Apr  3 16:42:32 2013
@@ -1,0 +1,42 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2013 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# This program is distributed in the hope that it will be useful,            
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""Module for handling Python lists."""
+
+
+def count_unique_elements(values=None):
+    """Count the number of unique instances in the given list.
+
+    @keyword values:    The list of values to count.
+    @type values:       list
+    @return:            The number of unique instances.
+    @rtype:             int
+    """
+
+    # Create a new list.
+    new_list = []
+    for i in values:
+        if i not in new_list:
+            new_list.append(i)
+
+    # The number.
+    return len(new_list)




Related Messages


Powered by MHonArc, Updated Wed Apr 03 17:00:02 2013