[Zope] Grabbing an item from a list of tuples

Toby Dickenson tdickenson@geminidataloggers.com
Fri, 19 Jul 2002 16:38:12 +0100


On Friday 19 Jul 2002 4:33 pm, abg@comco-inc.com wrote:
> I am writing a script which returns a list of tuples, like so:
>
> [('http://www.news.com/frontdoor/0-1.html?tag=3Dhd_ts', 'CNET'),
> ('http://www.news.com/shopping/0-1257.html?tag=3Dhd_ts', 'Price
> comparisons')]
>
> My question (and it's a dumb one) is: how do I refer to the individual
> values within the tuples when iterating through the list?
>
> Here's what I've got so far:
>
> myCount =3D 0
>
> for elem in p.anchors:
> =09for elem in elem:
> =09=09print myCount, ": ", elem[0:]
> =09=09myCount =3D myCount + 1
>
> Here's what it returns:
>
> 0 :  http://www.news.com/frontdoor/0-1.html?tag=3Dhd_ts
> 1 :  CNET
> 2 :  http://www.news.com/shopping/0-1257.html?tag=3Dhd_ts
> 3 :  Price comparisons
>
> How can I specifically reference the urls/titles separately?

myCount =3D 0
for url,title in p.anchors:
    print url, title=20
    myCount +=3D 1