requestion regarding regular expression
Felipe Almeida Lessa
felipe.lessa at gmail.com
Fri Apr 14 10:56:19 EDT 2006
Em Sex, 2006-04-14 às 07:47 -0700, BartlebyScrivener escreveu:
> starts = [i for i, line in enumerate(lines) if
> line.startswith('(defun')]
This line makes a list of integers. enumerate gives you a generator that
yields tuples consisting of (integer, object), and by "i for i, line"
you unpack the tuple into "(i, line)" and pick just "i".
> for i, start in starts:
Here you try to unpack the elements of the list "starts" into "(i,
start)", but as we saw above the list contains just "i", so an exception
is raised.
I don't know what you want, but...
starts = [i, line for i, line in enumerate(lines) if
line.startswith('(defun')]
or
starts = [x for x in enumerate(lines) if x[1].startswith('(defun')]
...may (or may not) solve your problem.
--
Felipe.
More information about the Python-list
mailing list