Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | def count_truthy(items): |
||
2 | """ |
||
3 | Count non None values viz, but includes 0 |
||
4 | ---- |
||
5 | examples: |
||
6 | |||
7 | 1) count_truthy([1, 2, None, 'a']) -> 3 |
||
8 | 2) count_truthy([1, 2, 0, 'a']) -> 4 |
||
9 | ---- |
||
10 | :param items: list |
||
11 | :return: int |
||
12 | """ |
||
13 | counter = 0 |
||
14 | for item in items: |
||
15 | if item is not None: |
||
16 | counter += 1 |
||
17 | return counter |
||
18 | |||
19 | |||
20 | def to_camel_case(snake_str): |
||
21 | """ |
||
22 | Convert snake case to CamelCase |
||
23 | ----- |
||
24 | examples: |
||
25 | |||
26 | 1) to_camel_case('snake_cased_string') -> 'SnakeCasedString' |
||
27 | ----- |
||
28 | :param snake_str: str |
||
29 | :return: str |
||
30 | """ |
||
31 | components = snake_str.split('_') |
||
32 | return components[0].title() + ''.join(x.title() for x in components[1:]) |
||
33 |