Pythonic way to select element in a list window
Write functions, improvements can range from faster code to the ability to reliably time or profile your code.
You don't need to use else if you're just using pass in that block.
Your code is WET, so it's not DRY. Instead of duplicating the code, you could instead assign to a variable in the if and else, to check against.
You may want to get into a habit of using if __name__ == '__main__':. In short, if you import the file it won't run the code.


This can get you:

def rename_me(l, seuil):
    new_l = []
    index = []
    for i, elt in enumerate(l):
        bound = 1 if elt &gt; seuil else seuil
        try:
            if (l[i-1] and l[i+1]) &gt; bound:
                new_l.append(elt)
                index.append(i)
        except IndexError:
            pass
    return index, new_l




A couple more things:


I think you have a bug, (l[i-1] and l[i+1]) &gt; bound probably isn't doing what you think it is. It's only checking if l[i+1] is greater than bound. As 1 and 2 == 2 and 0 and 2 == 0 are both true. Instead you may want to use l[i-1] &gt; bound &lt; l[i+1].
I don't see why you'd need the indexes and the elements from the original list, and so you could instead just return one or the other.
You can change the function to be a generator function, as this reduces memory usage.
You could use a modified itertools.pairwise, to remove the IndexError.




from itertools import tee

def rename_me(l, seuil):
    a, b, c = tee(l, 3)
    next(b, None)
    next(c, None)
    next(c, None)
    for index, (i, j, k) in enumerate(zip(a, b, c), 1):
        if i &gt; (1 if j &gt; seuil else seuil) &lt; k:
            yield index