Try changing all instances of list[i + 1] to list[i] On Thu, Jul 16, 2009 at 8:33 AM, Eduardo Vieira <eduardo.su...@gmail.com>wrote:
> #=== > I tried this version to post in this forum but that gives me an error. > I don't know why I don't get an error with the code above which is > essentially the same: > # -*- coding: cp1252 -*- > > result = '' > lista = [ > 'No', ',', 'thank...@+', > 'He', 'said', ',', '"', 'no', ',', 'thanks', '.', '"', 'OK', '?', 'Hi'] > > punct = '!#$%)*,-.:;<=>?@/\\]^_`}~”…' > for i, item in enumerate(lista): > > if item == '"' and lista[i + 1] not in punct: > result +=item > spacer = True > elif '+...@+' in item: > donewline = item.replace('+...@+','\n ') > result += donewline > elif item not in punct and lista[i + 1] in punct: > result += item > elif item in punct and lista[i + 1] in punct: > result += item > elif item in punct and lista[i + 1] == '"' and spacer: > result += item > spacer = False > elif item not in punct and lista[i + 1] == '"' and spacer: > result += item > spacer = False > elif item in '([{“': > result += item > else: > result += (item + " ") > > print result > > #== > The error is this: > Traceback (most recent call last): > File "<string>", line 244, in run_nodebug > File "C:\mytools\jointags-v4.py", line 17, in <module> > elif item not in punct and lista[i + 1] in punct: > IndexError: list index out of range > > I'm using python 2.6.2 with PyScripter IDE > I have tried a so many variations that I'm not sure what I'm doing any > more.... > I'm just trying to avoid some post-processing with sed again. > > Thankful, > > Eduardo > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- http://alitechtips.blogspot.com/
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor