From 84cef33abe0cb9e279271d90be4bb532329252a0 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Tue, 9 Sep 2003 02:01:12 +0000 Subject: [PATCH] added list2dict, uniqueElements --- direct/src/showbase/PythonUtil.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index ac97a77225..cb25c72344 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/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