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 <[email protected]> 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]) for x in c)
>
> print r[3]
>
> UKG
>
> Method III
> ----------
> Anything better than the above two?

Reply via email to