Okay, here I have another problem, I need to find position of \n alone in my list.
list = ['abc', '\n', 'def', 'ghi', '\n', 'jkl']
So, I need to get the position of all ‘\n’ entries from this list.
I used
a=list.index('\n')
but got only one value as ‘1’. How to get both positions?
e.g. I will get a list with the position of ‘\n’
position = [‘1’, ‘4’]
‘1’ represents first position of \n in list and the ‘4’ represents second at the fourth place in list.
You’ll need to iterate over the elements. This can be easily done by using a list comprehension and
enumeratefor the indexes:Demo: