python - list.reverse does not return list? -
the return object named none
list.reverse()
. code fails when call solution(k)
. there way can around making temporary? or how should it?
fcamel = 'f' bcamel = 'b' gap = ' ' k = ['f', ' ', 'b', 'f'] def solution(formation): return ((formation.index(bcamel) > (len(formation) - 1 - (formation.reverse()).index(fcamel))))
p.s. first code in python. thought functional.
you can use reversed(formation)
return reverse iterator of formation
. when call formation.reverse()
in place reversal of list , returns none.
edit:
i see trying now, in opinion it's easier list comprehension:
def solution(formation): return len([k k in formation[formation.index(bcamel)+1:] if k == fcamel]) == 0
this looks @ elements after first bcamel
, collects elements have value fcamel
. if list has length == 0 have solution.
here's few examples:
>>> k = ['f','f','b','b','f'] >>> solution(k) false >>> k = ['f','f','b','b','b'] >>> solution(k) true >>> k = ['f','f','b','f','f','b','b'] >>> solution(k) false >>>
Comments
Post a Comment