Python3 two short solutions using with statement - The Dining Philosophers
With one lock:\n\nimport threading\n\nclass DiningPhilosophers:\n\n    def __init__(self):\n        self.lock = threading.Lock()\n\n    # call the functions dir
With one lock:\n```\nimport threading\n\nclass DiningPhilosophers:\n\n    def __init__(self):\n        self.lock = threading.Lock()\n\n    # call the functions directly to execute, for example, eat()\n    def wantsToEat(self,\n                   philosopher: int,\n                   pickLeftFork: \'Callable[[], None]\',\n                   pickRightFork: \'Callable[[], None]\',\n                   eat: \'Callable[[], None]\',\n                   putLeftFork: \'Callable[[], None]\',\n                   putRightFork: \'Callable[[], None]\') -> None:\n        with self.lock:\n            pickLeftFork()\n            pickRightFork()\n            eat()\n            putRightFork()\n            putLeftFork()\n```\n\nWith 5 locks, each philosopher acquire lower numbered lock first. For philosopher 0 and 4, they both want to acquire lock 0 first, so no deadlock.\n```\nimport threading\n\nclass DiningPhilosophers:\n    def __init__(self, num=5):\n        self.locks = [threading.Lock() for _ in range(num)]\n        self.orders = [sorted([i, (i+1) % num]) for i in range(num)]\n\n    # call the functions directly to execute, for example, eat()\n    def wantsToEat(self,\n                   philosopher: int,\n                   pickLeftFork: \'Callable[[], None]\',\n                   pickRightFork: \'Callable[[], None]\',\n                   eat: \'Callable[[], None]\',\n                   putLeftFork: \'Callable[[], None]\',\n                   putRightFork: \'Callable[[], None]\') -> None:\n        assert 0 <= philosopher < len(self.orders)\n        with self.locks[self.orders[philosopher][0]]:\n            with self.locks[self.orders[philosopher][1]]:\n                pickLeftFork()\n                pickRightFork()\n                eat()\n                putLeftFork()\n                putRightFork()\n```\t\nModified based on @alvarosanchezpalomino\'s feedback.
['Python', 'Python3']