diff options
author | Muriithi Frederick Muriuki | 2021-07-23 09:01:12 +0300 |
---|---|---|
committer | Muriithi Frederick Muriuki | 2021-07-23 09:01:12 +0300 |
commit | 5493c890c27373530a0212361d4632df613d8afd (patch) | |
tree | 6222723c157fd83da80fdf5ed867a5709cef0073 | |
parent | eb5bf7fbd66abfc798bc272a4aefcb972f61c55f (diff) | |
download | genenetwork3-5493c890c27373530a0212361d4632df613d8afd.tar.gz |
Extract function to flatten list of lists
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi
* gn3/computations/slink.py: Extract the `__flatten_list_of_lists` function
since it is used in more than one place.
-rw-r--r-- | gn3/computations/slink.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py index 0c74789..7ee9b5e 100644 --- a/gn3/computations/slink.py +++ b/gn3/computations/slink.py @@ -64,10 +64,13 @@ raise an exception.""" def zero_or_positive(val): return val >= 0; # flatten lists - flattened = [distance for child in lists for distance in child] + flattened = __flatten_list_of_lists(lists) if not all(map(zero_or_positive, flattened)): raise ValueError("Distances should be positive.") +def __flatten_list_of_lists(parent): + return [item for child in parent for item in child] + def nearest(lists, i, j): """ Computes shortest distance between member(s) in `i` and member(s) in `j`. |