Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .spellcheck_exceptions_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ piNY
psf
tzYhv
https
dev
lmCu
ro
wz
iter
tp
typeobj


# pythons implementations:
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- An in-depth study of Python's:
- Interpreter.
- This focuses on [CPython](https://github.com/python/cpython).
- [Annotations on the actual interpreter implementation](https://github.com/praisetompane/python_implementation_study_cpython)
- They are prefixed with "Praise:"
- Python's design, implementation and ecosystem.

## Language Details
Expand All @@ -24,27 +26,30 @@
- structuring projects:
- [package index](https://pypi.org)
- [extending and embedding](https://docs.python.org/3.11/extending/index.html)
- [PEP Index](https://www.python.org/dev/peps/)
- [developer contribution guide](https://devguide.python.org/)
- memory model:
- [computational complexity cost model](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-fall-2011/pages/readings/python-cost-model/)
- history:
- [The Story of Python, by Its Creator, Guido van Rossum](https://www.youtube.com/watch?v=J0Aq44Pze-w)

## Testing
- [pytest](https://docs.pytest.org/en/latest/index.html#)
## Community
- [Discord](https://discuss.python.org)

## Use Cases
- [Applications of Python](https://www.python.org/about/apps/)

## Learning Resources
- [roadmap](https://roadmap.sh/python)
- [practice problems](https://www.hackerrank.com/domains/python?filters%5Bstatus%5D%5B%5D=unsolved&badge_type=python)
- [What Does It Take To Be An Expert At Python?](https://www.youtube.com/watch?v=7lmCu8wz8ro)

## Spell Check
```shell
pyspelling -c spellcheck.yaml
```


# References:

## Legend:
Expand Down
1 change: 0 additions & 1 deletion application_projects/README.md

This file was deleted.

1 change: 0 additions & 1 deletion application_projects/run_project.sh

This file was deleted.

Binary file modified dictionary.dic
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def fibonacci():
a = 0
b = 1
while True:
yield a
a = b
b = a + b


for n in fibonacci():
if n > 50:
break
print(n)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class RemoteControlIterator:
def __init__(self):
self.channels = ['HBO', 'SABC2', 'MNET', 'ESPN']
self.current_channel = -1

def __iter__(self):
return self

def __next__(self):
self.current_channel += 1
if self.current_channel == len(self.channels):
raise StopIteration

return self.channels[self.current_channel]


if __name__ == "__main__":
r = RemoteControlIterator()

try:
print(f"Channel {next(r)}")
except StopIteration:
print("All Channel Explored. Goodbye")
File renamed without changes.
70 changes: 70 additions & 0 deletions standard_library/3_built_in_types/4_iterator_types/0_iterators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
def iterator:
- formal:
- in words: an object that represents a stream of data.

- properties:
- forward and reserve traversal.
- can only be traversed once.
- plain english: ???

- intuition: ???

- properties: ???

- examples: ???

- use cases: ???

- proof: None. It is a definition.

References:
PEP 234 – Iterators. https://peps.python.org/pep-0234/
"""

collection = [i for i in range(5)]

print("Forward Iteration with next(forward_iterator)")
forward_iterator = iter(collection)
print(f"Type: {type(forward_iterator)}")
print(f"Print next element {next(forward_iterator)}")
print(f"Print next element {next(forward_iterator)}")
print(f"Print next element {next(forward_iterator)}")
print(f"Print next element {next(forward_iterator)}")
print(f"Print next element {next(forward_iterator)}")
# print(f"Print next element {next(forward_iterator)}")
print("\n")

print("Forward Iteration with __next__")
forward_iterator_2 = iter(collection)
print(f"Print next element {forward_iterator_2.__next__()}")
print(f"Print next element {forward_iterator_2.__next__()}")
print(f"Print next element {forward_iterator_2.__next__()}")
print(f"Print next element {forward_iterator_2.__next__()}")
print(f"Print next element {forward_iterator_2.__next__()}")
# print(f"Print next element {forward_iterator)}")
print("\n")

print("Reverse Iteration")
reverse_iterator = reversed(collection)
print(f"Type: {type(forward_iterator)}")
print(f"Print next element {next(reverse_iterator)}")
print(f"Print next element {next(reverse_iterator)}")
print(f"Print next element {next(reverse_iterator)}")
print(f"Print next element {next(reverse_iterator)}")
print(f"Print next element {next(reverse_iterator)}")
# print(f"Print next element {next(reverse_iterator)}")
print("\n")

# Single Travel Example
collection = [i for i in range(5)]
iterator = iter(collection)

print("First pass of the iterator")
for v in iterator:
print(v)

# This next pass will fail, because we have exhausted the iterator's single pass
print("Second pass of the iterator")
for v in iterator:
print(v)
43 changes: 43 additions & 0 deletions standard_library/3_built_in_types/4_iterator_types/1_generators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
def generator | generator function:
- formal: 𝑓: any ↦ Generator Iterator
- in words: a function that creates and returns a Generator Iterator.

- plain english: ???

- intuition: ???

- properties: ???

- examples:
- useful example: src/applications/math/fibonacci.py

- use cases: ???

- proof: None. It is a definition.

References:
PEP 255 – Simple Generators. https://www.python.org/dev/peps/pep-0255/#motivation

"""


def generate_infinite_numbers():
"""
Generate infinite numbers
"""
number = 0
while True:
yield number
number += 1


def generator_expression():
sum(i * i for i in range(10))


if __name__ == "__main__":
for number in generate_infinite_numbers():
print(number)

# print(generator_expression())