I have the following array(in python):
arr= ['\n', ' a#B\n', ' c#D\n']
Now I an trying to split on ‘#’ for which I am writing the code given below:
for i in arr:
g=i.split("#")[1]
I am getting the following error:
g=i.split("#")[1]
IndexError: list index out of range
I am not getting why am I getting the error. Can someone be kind enough to help rectify it.
When the first element of your list,
'\n'is assigned toiit does not contain"#", so the result list is only one element long, not two. Attempting to retrieve index1fails, but index0would be present.