How to find exact place for given value in python dictionary? -
i have 1 dictionary key , value. key row name , values last seat number. find row number based on input value.
seats_dict={'a':10,'b':'20':'c':30} input:
seat_num =16
output: should 'b'
is there function identity in python?
given boundary values 1 30. row 10 seats... you're better of building list of values, indexing, eg:
seats = ''.join(row * 10 row in 'abc') # add defg etc.. additional rows try: print seats[15] # note python indices 0 based except indexerror: pass # no row found - that way can naturally check boundaries / add more rows - change seat sizes each row...
you can include rows using nested list-comp, eg:
seats = ['{}{}'.format(r, n) r in 'abc' n in range(1, 11)] #['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'b10', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] then index same above - eg: seats[15] gives 'b6'
Comments
Post a Comment