Simple python solution using lock ordering
Intuition\n Describe your first thoughts on how to solve this problem. \nTake locks in sorted order. Philosopher 0 must take fork 0 before he takes fork 1, this
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTake locks in sorted order. Philosopher 0 must take fork 0 before he takes fork 1, this means philosopher 4 takes fork 0 before he takes fork 4.\n\nSo only one of them will take the fork 0 and the other will wait. Since we have to have one who doesn\'t take anything that means that the the one next to him will be able to get two.\n\n\n# Code\n```\nfrom threading import Lock, Semaphore\n\nclass DiningPhilosophers:\n\n    def __init__(self):\n        self.forks = [Lock() for _ in range(5)]\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\n        left, right = self.left_fork(philosopher), self.right_fork(philosopher)\n\n        if left > right:\n            left, right = right, left\n            pickLeftFork, pickRightFork = pickRightFork, pickLeftFork\n            putLeftFork, putRightFork = putRightFork, putLeftFork\n        \n        with self.forks[left]:\n            pickLeftFork()\n            with self.forks[right]:\n                pickRightFork()\n                eat()\n        \n            putLeftFork()\n            putRightFork()\n\n    def left_fork(self, i):\n        return (i + 1) % 5\n    \n    def right_fork(self, i):\n        return i\n```
['Python3']