diff --git a/.spellcheck_exceptions_dictionary.txt b/.spellcheck_exceptions_dictionary.txt index 45240ac..b034bbf 100644 --- a/.spellcheck_exceptions_dictionary.txt +++ b/.spellcheck_exceptions_dictionary.txt @@ -94,6 +94,13 @@ piNY psf tzYhv https +dev +lmCu +ro +wz +iter +tp +typeobj # pythons implementations: diff --git a/README.md b/README.md index 72eb958..ed72e94 100644 --- a/README.md +++ b/README.md @@ -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 @@ -24,14 +26,15 @@ - 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/) @@ -39,12 +42,14 @@ ## 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: diff --git a/application_projects/README.md b/application_projects/README.md deleted file mode 100644 index 65d936c..0000000 --- a/application_projects/README.md +++ /dev/null @@ -1 +0,0 @@ -# larger implementations to test understanding of the language and its strengths/weaknesses diff --git a/application_projects/run_project.sh b/application_projects/run_project.sh deleted file mode 100755 index dd5c79f..0000000 --- a/application_projects/run_project.sh +++ /dev/null @@ -1 +0,0 @@ -pipenv run python main.py \ No newline at end of file diff --git a/dictionary.dic b/dictionary.dic index 88cad2f..bcba6bc 100644 Binary files a/dictionary.dic and b/dictionary.dic differ diff --git a/src/applications/math/triangularNumbers.py b/src/applications/math/triangular_numbers.py similarity index 100% rename from src/applications/math/triangularNumbers.py rename to src/applications/math/triangular_numbers.py diff --git a/src/applications/standard_library/3_built_in_types/4_iterator_types/fibonacci.py b/src/applications/standard_library/3_built_in_types/4_iterator_types/fibonacci.py new file mode 100644 index 0000000..5b7fe00 --- /dev/null +++ b/src/applications/standard_library/3_built_in_types/4_iterator_types/fibonacci.py @@ -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) diff --git a/src/applications/standard_library/3_built_in_types/4_iterator_types/remote_control.py b/src/applications/standard_library/3_built_in_types/4_iterator_types/remote_control.py new file mode 100644 index 0000000..700ec58 --- /dev/null +++ b/src/applications/standard_library/3_built_in_types/4_iterator_types/remote_control.py @@ -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") \ No newline at end of file diff --git a/src/applications/collections/__init__.py b/src/applications/standard_library/3_built_in_types/5_sequence_types/__init__.py similarity index 100% rename from src/applications/collections/__init__.py rename to src/applications/standard_library/3_built_in_types/5_sequence_types/__init__.py diff --git a/src/applications/collections/rangeimplementation.py b/src/applications/standard_library/3_built_in_types/5_sequence_types/range_implementation.py similarity index 100% rename from src/applications/collections/rangeimplementation.py rename to src/applications/standard_library/3_built_in_types/5_sequence_types/range_implementation.py diff --git a/src/_io/simpleTable.py b/src/io/simple_table.py similarity index 100% rename from src/_io/simpleTable.py rename to src/io/simple_table.py diff --git a/standard_library/3_built_in_types/4_iterator_types/0_iterators.py b/standard_library/3_built_in_types/4_iterator_types/0_iterators.py new file mode 100644 index 0000000..d65e240 --- /dev/null +++ b/standard_library/3_built_in_types/4_iterator_types/0_iterators.py @@ -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) diff --git a/standard_library/3_built_in_types/4_iterator_types/1_generators.py b/standard_library/3_built_in_types/4_iterator_types/1_generators.py new file mode 100644 index 0000000..57f98ab --- /dev/null +++ b/standard_library/3_built_in_types/4_iterator_types/1_generators.py @@ -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())