The return object is named None
for list.reverse()
. So this code fails when I call solution(k)
. Is there any way I can get around making a temporary? Or how should I do 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. This is my first code in python. I thought it was functional.
The reverse() method doesn't return any value. It updates the existing list.
The list. reverse() method returns None because it reverses the list in place. It doesn't return a new reversed list.
Method 1: Reversing a list using the reversed() and reverse() built-in function. Using the reversed() method and reverse() method, we can reverse the contents of the list object in place i.e., we don't need to create a new list instead we just copy the existing elements to the original list in reverse order.
Python reversed() method returns an iterator that accesses the given sequence in the reverse order.
You can use slicing to return the reversed list:
l[::-1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With