Q: need to print attribute value only once if that attribute value comes again it should ignore that consider a table testing where attributes are (id,test_case,file_name,coverage)
as i'll get multiple file_name as input from a list i need to display test_case attribute value only once. here is below example:
import MySQLdb
out1=list()
out1=['cdp.c',ndp_arp_fusen.c','discovery.c']
db=MySQLdb.connect(host="localhost",user="root",passwd="vinay123",db="test")
cur=db.cursor()
for line in out1:
    cur.execute("select * from check2 where file_name like %s",("%"+line))
    rows=cur.fetchall()
    for row in rows:
        print(row)

i'm getting output as below:
(3917L, 'test case1', 'cdp.c', 1L)
(7730L, 'test case2', 'cdp.c', 937L)
(9837L, 'test case3', 'cdp.c', 888L)
(11313L, 'test case4', 'cdp.c', 89L)
(15727L, 'test case5', 'cdp.c', 937L)
(19718L, 'test case6', 'cdp.c', 1L)
(25003L, 'test case7', 'cdp.c', 937L)
(25004L, 'test case7', 'cdp.c', 1L)
(25239L, 'test case8', 'cdp.c', 937L)
(25240L, 'test case8', 'cdp.c', 1L)
(3970L, 'test case1', 'ndp_arp_fusen.c', 81L)
(7780L, 'test case2', 'ndp_arp_fusen.c', 83L)
(15777L, 'test case5', 'ndp_arp_fusen.c', 83L)
(19771L, 'test case6', 'ndp_arp_fusen.c', 81L)
(25083L, 'test case7', 'ndp_arp_fusen.c', 83L)
(25084L, 'test case7', 'ndp_arp_fusen.c', 81L)
(3971L, 'test case1', 'discovery.c', 34L)
(7781L, 'test case2', '_discovery.c', 34L)
(9887L, 'test case3', 'discovery.c', 34L)
(10239L, 'test case4', 'discovery.c', 34L)
(15778L, 'test case5', 'discovery.c', 34L)
(19772L, 'test case6', 'discovery.c', 34L)
(25085L, 'test case7', 'discovery.c', 34L)
(25321L, 'test case8', 'discovery.c', 34L)

as i need test_case attribute values to print unique,that is i dont need duplicate test_case name.
i require test_case name only once,output should be as below:
(3917L, 'test case1', 'cdp.c', 1L)
(7730L, 'test case2', 'cdp.c', 937L)
(9837L, 'test case3', 'cdp.c', 888L)
(11313L, 'test case4', 'cdp.c', 89L)
(15727L, 'test case5', 'cdp.c', 937L)
(19718L, 'test case6', 'cdp.c', 1L)
(25003L, 'test case7', 'cdp.c', 937L)
(25239L, 'test case8', 'cdp.c', 937L)


A: You could save seen values in a set to remember what values have already been printed, and skip them:
seen = set()
for line in out1:
    cur.execute("select * from check2 where file_name like %s",("%"+line))
    rows=cur.fetchall()
    for row in rows:
        if row[1] in seen:
            continue
        else:
            seen.add(row[1])
            print(row)

