added list2dict, uniqueElements
This commit is contained in:
parent
8e4f715798
commit
84cef33abe
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue