Parsing lists
Peter Schneider-Kamp
petersc at stud.ntnu.no
Sun Jul 9 04:35:07 EDT 2000
Seamus Venasse wrote:
>
> I am creating a simple list of titles and urls. I would like to parse this
> list, but I keep receiving an error. Here is a simplified version of my
> code and error received:
>
> >>> list = [ 'title1', 'url1', 'title2', 'url2', 'title3', 'url3' ]
> >>> for title, url in list:
> ... print title, url
> ...
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> ValueError: unpack sequence of wrong size
If you are using this form of the for-loop you need your list be
a list of sequences (e.g. tuples, lists). In your example:
list = [ ('title1', 'url1'), ('title2', 'url2'), ('title3', 'url3') ]
for title, url in list:
print title, url
If possible change the structure of your list accordingly.
Good luck,
Peter
--
Peter Schneider-Kamp ++47-7388-7331
Herman Krags veg 51-11 mailto:peter at schneider-kamp.de
N-7050 Trondheim http://schneider-kamp.de
More information about the Python-list
mailing list