# Pygredients
Version 0.1.3
Pygredients is an open-source Python library for data structures, algorithms and design patterns available on PyPi. 🍎🍊🍋🫐
## Installation
You can install Pygredients using pip:
```
pip install pygredients
```
For macOS users, please use the following command:
```
pip3 install pygredients
```
## Usage
To use Pygredients in your Python code, import it as follows:
```python
import pygredients
```
# Data Structures
## Linked List
You can create a linked list, add nodes to it, remove nodes from it, and perform other operations using the `LinkedList` class.
```python
# Create a linked list
ll = LinkedList()
# Add a node to the linked list
ll.append(1)
ll.append(2)
ll.append(3)
# Remove a node from the linked list
ll.remove(2) # 2
# Check if a value is in the linked list
ll.contains(1) # True
# Get the head of the linked list
ll.peek() # 3
# Get the length of the linked list
ll.size() # 2
# Check if the linked list is empty
ll.is_empty() # False
# Print the linked list
print(ll) # [1, 3]
# Limit the length of the linked list
ll.limit = 2
ll.append(4) # ValueError: Cannot append 4 to Linked List as it is full.
```
## Stack
You can create a stack, push values onto it, pop values from it, and perform other operations using the `Stack` class.
```python
# Create a stack
stack = Stack()
# Push a value to the stack
stack.push(1)
stack.push(2)
stack.push(3)
# Pop a value from the stack
stack.pop() # 3
# Peek the top of the stack
stack.peek() # 2
# Check if a value is in the stack
stack.contains(1) # True
# Get the length of the stack
stack.size() # 2
# Check if the stack is empty
stack.is_empty() # False
# Print the stack
print(stack) # [1, 2]
# Limit the length of the stack
stack.limit = 2
stack.push(4) # ValueError: Cannot push 4 to Stack as it is full.
```
## Queue
You can create a queue, enqueue values into it, dequeue values from it, and perform other operations using the `Queue` class.
```python
# Create a queue
queue = Queue()
# Enqueue a value to the queue
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
# Dequeue a value from the queue
queue.dequeue() # 1
# Peek the front of the queue
queue.peek() # 2
# Check if a value is in the queue
queue.contains(1) # True
# Get the length of the queue
queue.size() # 2
# Check if the queue is empty
queue.is_empty() # False
# Print the queue
print(queue) # [2, 3]
# Limit the length of the queue
queue.limit = 2
queue.enqueue(4) # ValueError: Cannot enqueue 4 to Queue as it is full.
```
# Design Patterns
## Observer
The Observer pattern is implemented in Pygredients using the`Observer` and `Observable` classes. Here's an example usage:
```python
from pygredients.observer.observer import Observer, Observable
class WeatherStation(Observable):
pass
class DisplayDevice(Observer):
def __init__(self, name):
super().__init__(name)
self.temperature = None
def notify(self, *args, **kwargs):
self.temperature = kwargs.get('temperature')
print(f'{self.name} now displays the temperature: {self.temperature}°C')
# Initialize a WeatherStation and two DisplayDevices
station = WeatherStation()
device1 = DisplayDevice("Device1")
device2 = DisplayDevice("Device2")
# Register the DisplayDevices with the WeatherStation
station.register_observers(device1)
station.register_observers(device2)
# Update the state of the WeatherStation
station.state = {'temperature': 20}
# Unsubscribe device1 and update the state again
device1.unsubscribe()
station.state = {'temperature': 22}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/FBH514/pygredients",
"name": "pygredients",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "data structures algorithms design patterns",
"author": "Fran\u00e7ois Boulay-Handfield",
"author_email": "fbhworks@icloud.com",
"download_url": "https://files.pythonhosted.org/packages/c5/6b/c9a9ec9314ff1794b198737849e9eb276b3771fa0b6cd435b8faebbfd40b/pygredients-0.1.3.tar.gz",
"platform": null,
"description": "# Pygredients\n\nVersion 0.1.3\n\nPygredients is an open-source Python library for data structures, algorithms and design patterns available on PyPi. \ud83c\udf4e\ud83c\udf4a\ud83c\udf4b\ud83e\uded0\n\n## Installation\n\nYou can install Pygredients using pip:\n\n```\npip install pygredients\n```\n\nFor macOS users, please use the following command:\n\n```\npip3 install pygredients\n```\n\n## Usage\n\nTo use Pygredients in your Python code, import it as follows:\n\n```python\nimport pygredients\n```\n\n# Data Structures\n\n## Linked List\n\nYou can create a linked list, add nodes to it, remove nodes from it, and perform other operations using the `LinkedList` class.\n\n```python\n# Create a linked list\nll = LinkedList()\n\n# Add a node to the linked list\nll.append(1)\nll.append(2)\nll.append(3)\n\n# Remove a node from the linked list\nll.remove(2) # 2\n\n# Check if a value is in the linked list\nll.contains(1) # True\n\n# Get the head of the linked list\nll.peek() # 3\n\n# Get the length of the linked list\nll.size() # 2\n\n# Check if the linked list is empty\nll.is_empty() # False\n\n# Print the linked list\nprint(ll) # [1, 3]\n\n# Limit the length of the linked list\nll.limit = 2\nll.append(4) # ValueError: Cannot append 4 to Linked List as it is full.\n```\n\n## Stack\n\nYou can create a stack, push values onto it, pop values from it, and perform other operations using the `Stack` class.\n\n```python\n# Create a stack\nstack = Stack()\n\n# Push a value to the stack\nstack.push(1)\nstack.push(2)\nstack.push(3)\n\n# Pop a value from the stack\nstack.pop() # 3\n\n# Peek the top of the stack\nstack.peek() # 2\n\n# Check if a value is in the stack\nstack.contains(1) # True\n\n# Get the length of the stack\nstack.size() # 2\n\n# Check if the stack is empty\nstack.is_empty() # False\n\n# Print the stack\nprint(stack) # [1, 2]\n\n# Limit the length of the stack\nstack.limit = 2\nstack.push(4) # ValueError: Cannot push 4 to Stack as it is full.\n```\n\n## Queue\n\nYou can create a queue, enqueue values into it, dequeue values from it, and perform other operations using the `Queue` class.\n\n```python\n# Create a queue\nqueue = Queue()\n\n# Enqueue a value to the queue\nqueue.enqueue(1)\nqueue.enqueue(2)\nqueue.enqueue(3)\n\n# Dequeue a value from the queue\nqueue.dequeue() # 1\n\n# Peek the front of the queue\nqueue.peek() # 2\n\n# Check if a value is in the queue\nqueue.contains(1) # True\n\n# Get the length of the queue\nqueue.size() # 2\n\n# Check if the queue is empty\nqueue.is_empty() # False\n\n# Print the queue\nprint(queue) # [2, 3]\n\n# Limit the length of the queue\nqueue.limit = 2\nqueue.enqueue(4) # ValueError: Cannot enqueue 4 to Queue as it is full.\n```\n\n# Design Patterns\n\n## Observer\n\nThe Observer pattern is implemented in Pygredients using the`Observer` and `Observable` classes. Here's an example usage:\n\n```python\nfrom pygredients.observer.observer import Observer, Observable\n\n\nclass WeatherStation(Observable):\n pass\n\n\nclass DisplayDevice(Observer):\n def __init__(self, name):\n super().__init__(name)\n self.temperature = None\n\n def notify(self, *args, **kwargs):\n self.temperature = kwargs.get('temperature')\n print(f'{self.name} now displays the temperature: {self.temperature}\u00b0C')\n\n\n# Initialize a WeatherStation and two DisplayDevices\nstation = WeatherStation()\ndevice1 = DisplayDevice(\"Device1\")\ndevice2 = DisplayDevice(\"Device2\")\n\n# Register the DisplayDevices with the WeatherStation\nstation.register_observers(device1)\nstation.register_observers(device2)\n\n# Update the state of the WeatherStation\nstation.state = {'temperature': 20}\n\n# Unsubscribe device1 and update the state again\ndevice1.unsubscribe()\nstation.state = {'temperature': 22}\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pygredients is an open-source Python library for data structures, algorithms and design patterns available on PyPi.",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/FBH514/pygredients"
},
"split_keywords": [
"data",
"structures",
"algorithms",
"design",
"patterns"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5e538bf9e2da0530166897e8952a6458304fda27132198370978c64fde8266bc",
"md5": "20dc6f797e6cb9f7e9d218d32d560400",
"sha256": "72963c8f5e753e4eb65e197fa26c44aeb96d3c4a53f9d7f9e6bb6c38a4fbcb94"
},
"downloads": -1,
"filename": "pygredients-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "20dc6f797e6cb9f7e9d218d32d560400",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16654,
"upload_time": "2023-05-19T22:40:14",
"upload_time_iso_8601": "2023-05-19T22:40:14.937643Z",
"url": "https://files.pythonhosted.org/packages/5e/53/8bf9e2da0530166897e8952a6458304fda27132198370978c64fde8266bc/pygredients-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c56bc9a9ec9314ff1794b198737849e9eb276b3771fa0b6cd435b8faebbfd40b",
"md5": "dee924579ba6230786b113bf7b1adcae",
"sha256": "3c2396746b1f1104c6b6a26d53a50357596c38e8bda61ce1c5ae362923f77430"
},
"downloads": -1,
"filename": "pygredients-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "dee924579ba6230786b113bf7b1adcae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 13408,
"upload_time": "2023-05-19T22:40:16",
"upload_time_iso_8601": "2023-05-19T22:40:16.579863Z",
"url": "https://files.pythonhosted.org/packages/c5/6b/c9a9ec9314ff1794b198737849e9eb276b3771fa0b6cd435b8faebbfd40b/pygredients-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-19 22:40:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "FBH514",
"github_project": "pygredients",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pygredients"
}