Any help would be greatly appreciated. As you can see from what I have so far, my knowledge of the python language is...well...weak.
example:
oddrow([[1, 2], [9, 4], [7, 6]])
True
def oddrow(lst):
for item in lst:
if sum(item[0:n]) #lost
Any help would be greatly appreciated. As you can see from what I have so far, my knowledge of the python language is...well...weak.
example:
oddrow([[1, 2], [9, 4], [7, 6]])
True
def oddrow(lst):
for item in lst:
if sum(item[0:n]) #lost
Try the all
built-in:
Return True if all elements of the iterable are true (or if the iterable is empty).
So a list comprehension can map the oddness of the sum of the elements of one inner list into boolean space - e.g. the result for [[1, 2], [9, 4], [7, 6]]
would look like [True, True, True]
. And all
will do the rest.
def oddrow(lst):
return all([ sum(l) % 2 == 1 for l in lst ])
# since it's short, why not just make it a one-liner
oddrow = lambda lst: all([ sum(l) % 2 == 1 for l in lst ])