Explorar o código

added list2dict, uniqueElements

Darren Ranalli %!s(int64=22) %!d(string=hai) anos
pai
achega
84cef33abe
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  1. 9 1
      direct/src/showbase/PythonUtil.py

+ 9 - 1
direct/src/showbase/PythonUtil.py

@@ -23,7 +23,7 @@ def unique(L1, L2):
 
 def indent(stream, numIndents, str):
     """
-    Write str to stream with numIndents in front it it
+    Write str to stream with numIndents in front of it
     """
     # To match emacs, instead of a tab character we will use 4 spaces
     stream.write('    ' * numIndents + str)
@@ -348,6 +348,14 @@ def sameElements(a, b):
             return 0
     return 1
 
+def list2dict(L, value=None):
+    """creates dict using elements of list, all assigned to same value"""
+    return dict([(k,value) for k in L])
+
+def uniqueElements(L):
+    """are all elements of list unique?"""
+    return len(L) == len(list2dict(L))
+
 def contains(whole, sub):
     """
     Return 1 if whole contains sub, 0 otherwise