The thing I am trying to achieve is that I want to get the character before another one in a string. For e.g, if the string is "a0c1e2g3", I want to get what's written in the index[0] by just having the index[1] like i want to get the value of the index[0] ("a") when I only have the value of index[1] ("1"). I want it for all characters. I want the string to be extendable too. I am using python 3.10.1
Expected result:
a
c
e
g
The result I could get till:
0
2
4
6
The code I tried:
s = "a0c1e2g3"
for c, i in enumerate(s):
if i.isdigit():
alpha_before_int = c-1
print(alpha_before_int)
# I want to get "a", "c", "e", "g"
Halley Oliveira :
>>> s = "a0c1e2g3"\n>>> for c, i in enumerate(s):\n... if i.isdigit():\n... alpha_before_int = s[c-1]\n... print(alpha_before_int)\n... # I want to get "a", "c", "e", "g"\n... \na\nc\ne\ng\n>>> \n",
2021-11-02T13:35:24