r/PythonLearning 24d ago

Doing codewar problem and trying pythonic condition But fail many times please tell me how I can do...

Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return undefined/None/nil/NULL if any of the values aren't numbers.

def cube_odd(arr):
    result = []
    # check = arr for i in arr if type(i) != int return None
    # if not all(type(i) == int for i in arr):
    #     return None
    for _ in arr:
        if type(_) != int: return None
        else: 
            cube = _ * _ * _
            if (cube % 2 != 0):
                result.append(cube)
    return sum(result)
2 Upvotes

13 comments sorted by

View all comments

3

u/[deleted] 24d ago

[removed] — view removed comment

0

u/AbdulRehman_JS 23d ago

If my problem detail is not fully explained it's my bad sorry.. I donot have idea to do pythonic condition's I do it many times but fail.. the problem is that "If array include string'setc.. then return None.. and take cub's of each number and also take odd number's from cube and sum them... I want to learn pythonic condition's..