Filter Restaurants by Vegan-Friendly, Price and Distance LeetCode solution in Python

1
class Solution:
2
def f_fcn(self,restaurants, veganFriendly, maxPrice, maxDistance):
3
f_lst = filter(lambda x: (veganFriendly == 1 and x[2] == 1 and x[3] <= maxPrice and x[4] <= maxDistance) or
4
(veganFriendly == 0 and x[3] <= maxPrice and x[4] <= maxDistance), restaurants)
5
return f_lst
6

7
def h_fcn(self,lst):
8
return([lst[0], lst[1]])
9

10
def filterRestaurants(self, restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> List[int]:
11

12
res = map(self.h_fcn, self.f_fcn(restaurants, veganFriendly, maxPrice, maxDistance))
13

14

15
return map(lambda x: x[0], sorted(res, key=lambda x: (-x[1], -x[0])))

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0