Write a function called manipulate_data which will act as follows:

Tags: python
By : Olamide
Source: Stackoverflow.com
Question!

Write a function called manipulate_data which will act as follows:

When given a list of integers, return a list, where the first element is the count of positives numbers and the second element is the sum of negative numbers.

NB: Treat 0 as positive.

By : Olamide


Answers
def manipulate_data(data):
    if isinstance(data, (list, tuple, set)):
        #didn't know where 0 stood so I excluded it
        return [len([n for n in data if isinstance(n, int) and n > 0]), sum(n for n in data if isinstance(n, int) and n < 0)]
By : kenneth


The "using" keyword makes a member of an inherited class visible, and resolvable, in the scope of its subclass. So, to make the privately-inherited member available to B's subclasses:

class A {

protected:

    void foo() {}
};

class B : private A {

protected:

    using A::foo;
};

class C : public B {

    void bar()
    {
        foo();
    }
};


An item of type undefined (and it is a type) has no length property - only items of type string and array do. Therefore, as @redneb notes, extend your condition to check for a non-falsy value before checking length.

if (myVar && myVar.length) { ... }
By : Utkanos


This video can help you solving your question :)
By: admin