To "peek" at characters in a string preceding the current index, i
, is there a one-liner for avoiding negative indices? I want n
chars before the current char index of the string OR beginning of the string to current char.
My intuition says there might be something simple I can put in the same line as the list operation instead of another line to make an index. I'd rather avoid any libraries, and I'm aware a simple if
check would work... Hoping there's a magic operator I missed.
>>> s = 'ABCDEFG'
>>> s[0:5]
'ABCDE'
>>> s[-5:5]
'CDE'