[web2py] Re: Extracting data from a list having data in the format of a key, data

2011-02-26 Thread DenesL
On Feb 26, 10:04 am, Rupesh Pradhan wrote: > Method I > > c = [(1, 'NURSERY'), (2, 'LKG'), (3, 'UKG'), (4, '1')] > key=3 > > >>> for i, j in c: > > ... if i==key: print j > > UKG > > Method II > - > c = [(1, 'NURSERY'), (2, 'LKG'), (3, 'UKG'), (4, '1')] > r = dict((x[0],x[1]) fo

[web2py] Re: Extracting data from a list having data in the format of a key, data

2011-02-26 Thread Massimo Di Pierro
c = [(1, 'NURSERY'), (2, 'LKG'), (3, 'UKG'), (4, '1')] r = dict(c) print r[3] or print [x[1] for x in c if x[0]==3][0] On Feb 26, 9:04 am, Rupesh Pradhan wrote: > Method I > > c = [(1, 'NURSERY'), (2, 'LKG'), (3, 'UKG'), (4, '1')] > key=3 > > >>> for i, j in c: > > ... if i==key: prin