Asif,

You can iterate over a tuple. When doing that you reference the values 
directly. 
>From your example, data is a list containing a tuple. To check this, do this 
>from the prompt. 
type(data)
You should get:
<Type 'list'>

That said, your mistake is
On the if line. It should read:

 if value > 5:
And not what you wrote. 

For the purpose of another time, kindly paste the error message. With this we 
can point you to the direction of error. 

Also, indent he print command after the else: properly. 

Your new code should read this. 

data = [
    (10, 25, 18, 17, 10, 12, 26, 5),
    ]

for value in data:
     if value > 5:
                print " greater"
    else:
                print "lesser"


Sent from my BlackBerry wireless device from MTN

-----Original Message-----
From: Asif Jamadar <asif.jama...@rezayat.net>
Sender: bangpypers-bounces+delegbede=dudupay....@python.org
Date: Mon, 4 Jul 2011 06:24:48 
To: bangpypers@python.org<bangpypers@python.org>
Reply-To: Bangalore Python Users Group - India <bangpypers@python.org>
Subject: [BangPypers] Iterating list of tuples

Suppose I have list of tuples

data = [
    (10, 25, 18, 17, 10, 12, 26, 5),
    ]

for value in data:
     if data[value]>5:
                print " greater"
    else:
       print "lesser"

But the code giving me error so can I know how iterate list of tuples?

_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to