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
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
2 matches
Mail list logo