It seems silly to write the following:
L = []
if x in L:
L[x] = something
else:
L[x] = something_else
Doesn’t this perform the look-up for x twice? I tried using index(), but this gives an error when the value is not found.
Ideally I would like to say like:
if x is in L, save that index and:
...
I can appreciate that this might be a beginner python idiom, but it seems rather un-search-able. Thanks.
Another option is try/except:
Same result as your code.
Edit: Okay, fast moving target. Same idiom for a list, different exception (IndexError).