Completed
Pull Request — master (#17)
by Amresh
01:22
created

fastest.utils.to_camel_case()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
def count_truthy(items):
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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