list insertion question

eight02645999 at yahoo.com eight02645999 at yahoo.com
Tue Apr 17 03:05:16 CEST 2007


hi
i have a list (after reading from a file), say
data = [ 'a','b','c','d','a','b','e','d']

I wanted to insert a word after every 'a', and before every 'd'. so i
use enumerate this list:
for num,item in enumerate(data):
    if "a" in item:
	data.insert(num+1,"aword")
    if "d" in item:
        data.insert(num-1,"dword") #this fails
but the above only inserts after 'a' but not before 'd'.  What am i
doing wrong? is there better way?thanks




More information about the Python-list mailing list