You may use the built-in map()
to set the x
and y
variables.
def bla(self,x,y) :
for key in self.DataBase :
x,y = map(float, self.DataBase[key])
if x == dept and y == year:
return key
If you prefer using items()
, you may do the following as well (equally valid):
def bla(self,x,y):
for key, val in self.DataBase.items():
x, y = map(float, val)
if x == dept and y == year:
return key
Here's yet another way of doing it without map()
, this gives you the advantage of unpacking the tuples while iterating over the dict:
def bla(self,x,y):
for key, (x, y) in self.DataBase.items():
if x == dept and y == year:
return key
You may also write the above as so, using list comprehension, although I would say the one above is preferable:
def bla(self,x,y):
found = {key for key, (x, y) in self.DataBase.items() if x==dept and y==year}
found = ''.join(num) #joins set into string
return found
The following all work for Python 3, which I assume is what you want since one of your tags are Python 3.x