finding string in a list and return it index or -1
<p>Defining a procedure which return an index of item or -1 if the item not in list</p>

<pre><code>def ser(a,b):
    for j in a:
        if j == b:
            return (a.index(b))
        else:
            return -1

print (ser([1,2,3],3))
</code></pre>

<p>It's always return me -1. If i cut the 'else' part, it works. So why ?</p>

<p>You need not to do anything fancy, simple one-liner will work:</p>

<pre><code>def ser(a,b):
    return a.index(b) if b in a else -1

# Example
my_list = [1, 2, 3, 4]
ser(my_list, 2)
# returns: 1

ser(my_list, 8)
# returns: -1
</code></pre>

python list indexing