aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/slink.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/computations/slink.py')
-rw-r--r--gn3/computations/slink.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index 3156b31..b15c058 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -4,10 +4,11 @@ class LengthError(BaseException):
class MirrorError(BaseException):
pass
+def is_list_or_tuple(item):
+ return type(item) in [list, tuple]
+
def raise_valueerror_if_data_is_not_lists_or_tuples(lists):
"""Check that `lists` is a list of lists: If not, raise an exception."""
- def is_list_or_tuple(item):
- return type(item) == type([]) or type(item) == type(tuple)
if (not is_list_or_tuple(lists)) or (not all(map(is_list_or_tuple, lists))):
raise ValueError("Expected list or tuple")
@@ -72,7 +73,7 @@ This description should be updated once the form/type of 'distance' identified."
#### END: Guard Functions ####
if type(i) == int and type(j) == int: # From member i to member j
return lists[i][j]
- elif type(i) == int and (type(j) in [list, tuple]):
+ elif type(i) == int and is_list_or_tuple(j):
return min(map(lambda j_new: nearest(lists, i, j_new), j))
- elif type(j) == int and (type(i) in [list, tuple]):
+ elif type(j) == int and is_list_or_tuple(i):
return min(map(lambda i_new: nearest(lists, i_new, j), i))