Coverage for src/qollib/collections/reducing.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-02 08:34 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4The `reducing` utilities provides methods to reduce (dimensions) of arrays. 

5 

6@author: hoelken 

7""" 

8from typing import Iterable 

9 

10 

11def flatten_sorted(lists: Iterable) -> list: 

12 """Flattens a list of lists and sorts the result""" 

13 result = flatten(lists) 

14 result.sort() 

15 return result 

16 

17 

18def flatten(lists: Iterable) -> list: 

19 """Flattens a list of lists and sorts the result""" 

20 result = [] 

21 for entry in lists: 

22 if isinstance(entry, Iterable) and not isinstance(entry, (str, dict)): 

23 result.extend(flatten(entry)) 

24 else: 

25 result.append(entry) 

26 return result