├── 07_cpython └── readme.md ├── 01_python_fundamentals ├── 07_operators │ └── main.py ├── common_utils │ ├── __init__.py │ └── helper.py ├── 22_scope │ ├── example.txt │ └── main.py ├── 23_modules │ ├── 04_module_search_path │ │ ├── mypackage │ │ │ ├── __init__.py │ │ │ └── my_module.py │ │ ├── 01_extend_module │ │ │ ├── modules │ │ │ │ ├── __init__.py │ │ │ │ ├── main.py │ │ │ │ └── user.py │ │ │ └── common_utils │ │ │ │ ├── __init__.py │ │ │ │ └── helper.py │ │ └── main.py │ ├── 07_module_coding_basic │ │ ├── main.py │ │ └── module1.py │ ├── 01_import_and_attributes │ │ ├── c.py │ │ ├── main.py │ │ └── b.py │ ├── 08_module_namespace │ │ ├── module2.py │ │ ├── module_example.py │ │ └── main.py │ ├── 05_configuring_the_search_path │ │ └── main.py │ ├── 06_sys_path │ │ └── main.py │ ├── 09_reloading_modules │ │ └── changer.py │ └── 03_byte_code │ │ └── my_module.py ├── 03_character_sets │ └── main.py ├── 25_advance_module │ ├── 02_data_hiding_in_modules │ │ ├── underscore_example.py │ │ ├── module.py │ │ └── main.py │ ├── 05_changig_the_module_search │ │ └── main.py │ ├── 03_enable_future_feature │ │ └── main.py │ └── 04_mixed_usage_modes │ │ ├── main.py │ │ ├── greetings.py │ │ └── calculator.py ├── 24_modules_packages │ └── 01_package_import_basic │ │ ├── web_scraper │ │ ├── __init__.py │ │ ├── crawler │ │ │ ├── page_parser.py │ │ │ └── __init__.py │ │ └── utils │ │ │ ├── helper.py │ │ │ └── __init__.py │ │ └── main.py ├── 08_delimiters │ └── main.py ├── 04_tokens │ └── main.py ├── 21_working_with_files │ ├── logs.txt │ ├── logs_backup.txt │ └── main.py ├── 13_iterations │ └── main.py ├── 27_virtual_environment │ ├── Pipfile │ └── pyproject.toml ├── 26_testing_your_code │ ├── name_function.py │ ├── name.py │ ├── test_name_function.py │ ├── survey_program.py │ ├── survey.py │ └── test_survey.py ├── 20_regular_expressions │ └── 01_basic_regular_expressions │ │ ├── problem1.2.py │ │ ├── problem2.6.py │ │ ├── problem2.4.py │ │ ├── problem2.0.py │ │ ├── problem1.1.py │ │ ├── problem2.3.py │ │ ├── problem3.0.py │ │ ├── problem3.1.py │ │ ├── problem2.9.py │ │ ├── problem2.5.py │ │ ├── problem2.7.py │ │ ├── problem1.6.py │ │ ├── problem1.8.py │ │ ├── problem2.8.py │ │ ├── problem1.4.py │ │ ├── problem3.2.py │ │ ├── problem1.9.py │ │ ├── problem2.1.py │ │ ├── problem1.3.py │ │ ├── problem2.2.py │ │ ├── problem1.7.py │ │ └── problem1.5.py ├── 05_identifiers │ └── main.py ├── 02_lines_and_indentation │ └── main.py ├── 09_literals │ └── main.py ├── 18_dict │ └── exercise.md ├── 11_variables_as_references │ └── main.py ├── 17_set │ └── exercise.md └── 12_decisions_statements │ └── main.py ├── 02_object_oriented_programming ├── 08_lambda_expression │ ├── cart │ │ ├── __init__.py │ │ ├── models.py │ │ ├── tests.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── urls.py │ │ ├── views.py │ │ ├── static │ │ │ └── styles.css │ │ └── templates │ │ │ └── product.html │ ├── ecommerce │ │ ├── __init__.py │ │ ├── asgi.py │ │ ├── wsgi.py │ │ └── urls.py │ └── manage.py ├── 04_interfaces │ ├── 06_Project_Video │ │ └── readme.md │ ├── 01_tightly_coupled_code │ │ └── main.py │ ├── 02_creating_an_interface │ │ └── main.py │ └── 04_what_is_dependency_injection │ │ ├── 01_constructor_injection │ │ └── main.py │ │ ├── 03_method_injection │ │ └── main.py │ │ └── 02_setter_injection │ │ └── main.py ├── 13_customizing_typechecker │ ├── mypy.ini │ └── 01_configuring_type_checker │ │ └── main.py ├── 10_python_types │ ├── 01_typing_system_in_python │ │ ├── script.js │ │ └── main.py │ ├── main.py │ └── 02_understanding_ducky_typing │ │ └── main.py ├── 15_async_programming │ ├── 05_event_loop │ │ └── main.py │ ├── 08_async_generators │ │ └── main.py │ ├── 09_async_comprehensions │ │ └── main.py │ ├── 04_coroutine │ │ └── main.py │ ├── 02_async_walk │ │ └── main.py │ ├── 01_truth_about_threads │ │ ├── main.py │ │ ├── file1.txt │ │ ├── file2.txt │ │ └── file3.txt │ └── 07_async_iterators │ │ └── main.py ├── 14_defining_our_own_type │ ├── 03_user_defined_classes │ │ └── hashim_transcript.pdf │ ├── 02_advance_anums │ │ └── main.py │ ├── 10_decorator │ │ └── main.py │ └── 11_pydantic │ │ └── main.py ├── 02_inheritance │ ├── 09_abstract_classes_and_methods │ │ ├── example.py │ │ └── main.py │ ├── 08_polymorphism │ │ ├── data.csv │ │ ├── data.json │ │ └── data.xml │ ├── 03_constructors_and_inheritance │ │ └── main.py │ ├── 04_overriding_methods │ │ └── main.py │ ├── 02_the_object_class │ │ └── main.py │ ├── 01_inheritance │ │ └── main.py │ └── 10_callable_object │ │ └── main.py ├── 11_type_annotations │ ├── 02_benefits_of_type_annotations │ │ └── main.py │ ├── 04_optional_type │ │ ├── failure.py │ │ ├── main.py │ │ ├── user.py │ │ └── pizza_making_with_return.py │ ├── 06_literals │ │ └── main.py │ ├── 05_union_type │ │ └── main.py │ ├── 09_final │ │ └── main.py │ ├── 07_annotated │ │ └── main.py │ ├── 01_type_annotations │ │ └── main.py │ └── 08_newtype │ │ └── main.py ├── 01_Classes │ ├── 02_creating_a_class │ │ └── main.py │ ├── 05_encapsulation │ │ └── main.py │ ├── 04_procedural_programming │ │ └── main.py │ ├── 07_abstraction │ │ ├── 02_coupling │ │ │ └── main.py │ │ ├── 01_coupling │ │ │ └── main.py │ │ └── 03_abstraction │ │ │ └── main.py │ ├── 01_what_is_classes │ │ └── main.py │ ├── 06_getter_and_setter │ │ └── main.py │ ├── 08_constructor │ │ └── main.py │ ├── 10_constructor_overloading │ │ └── main.py │ └── 09_default_arguments │ │ └── main.py └── 12_collection_types │ ├── 01_annotated_collections │ └── main.py │ └── 03_typed_dict │ ├── main.py │ └── typedict.py ├── 06_python_projects_for_beginners └── readme.md ├── 05_design_patterns ├── 02_solid_principles │ ├── 01_single_responsible_principle │ │ ├── report.txt │ │ └── main.py │ ├── 03_liskov_substitution_principle │ │ └── main.py │ ├── 05_dependency_inversion_principle │ │ └── main.py │ ├── 02_open_closed_principle │ │ └── main.py │ ├── 04_interface_segregation_principle │ │ └── main.py │ └── readme.md ├── 01_foundation_design_principles │ ├── 03_interface_not_implemented_principle │ │ ├── log.txt │ │ ├── interfaces_bis.py │ │ └── interfaces.py │ ├── 02_composition_over_inheritance_principle │ │ ├── composition.py │ │ └── computer_composition.py │ ├── 01_encapsulate_principle │ │ ├── encapsulate.py │ │ └── encapsulate_bis.py │ └── 04_loose_coupling_principle │ │ └── loose_coupling.py └── 03_creational_design_patterns │ └── 01_factory_design_pattern │ ├── factory_method.py │ └── movies.json ├── assests ├── python-logo.png └── python-logo-white-bg.png ├── 04_algorithms ├── 07_searching │ ├── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ └── 03.jpg │ ├── unordered_linear_search.py │ └── search_ordered_list.py ├── 01_introducing_algorithm │ └── images │ │ └── 01.jpg ├── 02_analysis_of_an_algorithm │ └── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ └── 03.jpg └── 06_alogorithm_design_techniques_and_strategies │ ├── 05_greedy_algorithm │ └── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ ├── 03.jpg │ │ ├── 04.jpg │ │ ├── 05.jpg │ │ ├── 06.jpg │ │ ├── 07.jpg │ │ ├── 08.jpg │ │ ├── 09.jpg │ │ └── 10.jpg │ ├── 02_recursion_algorithm │ └── diagram │ │ ├── 01.jpg │ │ └── 02.png │ ├── 03_divide_and_conquer │ └── diagrams │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ ├── 03.jpg │ │ └── 04.jpg │ └── 04_dynamic_programming_technique │ └── images │ ├── 01.jpg │ ├── 02.jpg │ └── 03.jpg ├── .gitignore ├── 03_data_structures ├── 02_linked_list │ ├── 01_array │ │ └── images │ │ │ └── 01.jpg │ └── 02_linked_list │ │ ├── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ ├── 03.jpg │ │ └── 04.jpg │ │ ├── 01_singly_linked_list │ │ └── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 08.jpg │ │ │ └── 09.jpg │ │ ├── 02_doubly_linked_list │ │ └── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 08.jpg │ │ │ ├── 09.jpg │ │ │ ├── 10.jpg │ │ │ └── 11.jpg │ │ └── 03_circular_linked_list │ │ └── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ ├── circular_doubly │ │ ├── 01.jpg │ │ ├── 02.png │ │ └── 03.png │ │ └── circular_singly │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ ├── 03.jpg │ │ ├── 04.jpg │ │ └── 05.jpg ├── 04_trees │ ├── 02_binary_trees │ │ ├── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 08.jpg │ │ │ ├── 09.jpg │ │ │ ├── 10.jpg │ │ │ ├── 11.jpg │ │ │ ├── 12.jpg │ │ │ ├── 13.jpg │ │ │ ├── 14.jpg │ │ │ ├── 15.jpg │ │ │ ├── 16.jpg │ │ │ ├── 17.jpg │ │ │ ├── 18.jpg │ │ │ └── 19.jpg │ │ ├── postfix-expression-tree.py │ │ └── prefix-expression-tree.py │ ├── 03_binary_search_tree │ │ └── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 08.jpg │ │ │ ├── 09.jpg │ │ │ ├── 10.jpg │ │ │ ├── 11.jpg │ │ │ ├── 12.jpg │ │ │ ├── 13.jpg │ │ │ ├── 14.jpg │ │ │ ├── 15.jpg │ │ │ └── 16.jpg │ ├── 01_terminology_of_trees │ │ └── images │ │ │ └── 01.jpg │ └── readme.md ├── 03_stack_and_queues │ ├── 01_stack │ │ ├── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 08.jpg │ │ │ ├── 09.jpg │ │ │ └── 10.jpg │ │ ├── array-base-stack.py │ │ └── linkedlist-base-stack.py │ └── 03_queues │ │ └── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ ├── 03.jpg │ │ ├── 04.jpg │ │ ├── 05.jpg │ │ ├── 06.jpg │ │ ├── 07.jpg │ │ ├── 08.jpg │ │ ├── 09.jpg │ │ ├── 10.jpg │ │ ├── 11.jpg │ │ ├── 12.jpg │ │ ├── 13.jpg │ │ ├── 14.jpg │ │ └── 15.jpg ├── 00_datatype_and_object_in_python │ └── images │ │ ├── 01.jpg │ │ ├── 02.jpg │ │ └── 03.jpg ├── 07_graphs_and_algorithms │ ├── graphs │ │ ├── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 08.jpg │ │ │ ├── 09.jpg │ │ │ ├── 10.jpg │ │ │ ├── 11.jpg │ │ │ ├── 12.jpg │ │ │ ├── 13.jpg │ │ │ ├── 14.jpg │ │ │ ├── 15.jpg │ │ │ ├── 16.jpg │ │ │ ├── 17.jpg │ │ │ ├── 18.jpg │ │ │ ├── 19.jpg │ │ │ ├── 20.jpg │ │ │ ├── 21.jpg │ │ │ ├── 22.jpg │ │ │ ├── 23.jpg │ │ │ ├── 24.jpg │ │ │ ├── 25.jpg │ │ │ ├── 26.jpg │ │ │ ├── 27.jpg │ │ │ ├── 28.jpg │ │ │ ├── 29.jpg │ │ │ ├── 30.jpg │ │ │ ├── 31.jpg │ │ │ ├── 32.jpg │ │ │ ├── 33.jpg │ │ │ ├── 34.jpg │ │ │ ├── 35.jpg │ │ │ ├── 36.jpg │ │ │ ├── 37.jpg │ │ │ └── 38.jpg │ │ ├── breadth_first_search.py │ │ ├── graph.py │ │ └── depth-first-search.py │ └── readme.md ├── 05_heaps_and_periority_queues │ ├── 01_heaps │ │ └── images │ │ │ ├── 01.jpg │ │ │ ├── 02.jpg │ │ │ ├── 03.jpg │ │ │ ├── 04.jpg │ │ │ ├── 05.jpg │ │ │ ├── 06.jpg │ │ │ ├── 07.jpg │ │ │ ├── 09.jpg │ │ │ ├── 10.jpg │ │ │ ├── 11.jpg │ │ │ ├── 12.jpg │ │ │ ├── 13.jpg │ │ │ ├── 14.jpg │ │ │ ├── 15.jpg │ │ │ ├── 16.jpg │ │ │ ├── 17.jpg │ │ │ ├── 18.jpg │ │ │ └── 19.jpg │ ├── 02_priority_queues │ │ ├── images │ │ │ ├── 00.jpg │ │ │ ├── 01.jpg │ │ │ └── 03.png │ │ ├── priority-queue-heap.py │ │ └── main.py │ └── readme.md └── 06_hash_tables │ └── 01_Introducing_hash_tables │ ├── images │ ├── 01.png │ ├── 02.jpg │ ├── 03.jpg │ ├── 04.jpg │ ├── 05.jpg │ ├── 06.jpg │ ├── 07.jpg │ ├── 08.jpg │ ├── 09.jpg │ ├── 10.jpg │ ├── 11.jpg │ ├── 12.jpg │ ├── 13.jpg │ └── 14.jpg │ └── main.py └── LICENSE /07_cpython/readme.md: -------------------------------------------------------------------------------- 1 | # Cpython -------------------------------------------------------------------------------- /01_python_fundamentals/07_operators/main.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /01_python_fundamentals/common_utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /01_python_fundamentals/22_scope/example.txt: -------------------------------------------------------------------------------- 1 | This is safe! -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/ecommerce/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /06_python_projects_for_beginners/readme.md: -------------------------------------------------------------------------------- 1 | # Python Projects For Beginners -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/mypackage/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /01_python_fundamentals/03_character_sets/main.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | print("こんにちは, 世界!") 3 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/01_extend_module/modules/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/01_extend_module/common_utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/01_single_responsible_principle/report.txt: -------------------------------------------------------------------------------- 1 | This is the content. -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/02_data_hiding_in_modules/underscore_example.py: -------------------------------------------------------------------------------- 1 | a, _b, c, _d = 1, 2, 3, 4 -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/05_changig_the_module_search/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | print(sys.path) 3 | -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/03_enable_future_feature/main.py: -------------------------------------------------------------------------------- 1 | import __future__ 2 | print(dir(__future__)) -------------------------------------------------------------------------------- /assests/python-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/assests/python-logo.png -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/07_module_coding_basic/main.py: -------------------------------------------------------------------------------- 1 | import module1 2 | module1.printer("Hello world!") 3 | -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/03_interface_not_implemented_principle/log.txt: -------------------------------------------------------------------------------- 1 | File: A file log. 2 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/01_import_and_attributes/c.py: -------------------------------------------------------------------------------- 1 | # File: c.py 2 | 3 | def ham(text): 4 | print(f"{text} ham") 5 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/07_module_coding_basic/module1.py: -------------------------------------------------------------------------------- 1 | # File: module1.py 2 | 3 | def printer(x): 4 | print(x) 5 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/08_module_namespace/module2.py: -------------------------------------------------------------------------------- 1 | # File: module2.py 2 | name = "Muhammad Hashim" 3 | age = 24 4 | -------------------------------------------------------------------------------- /01_python_fundamentals/common_utils/helper.py: -------------------------------------------------------------------------------- 1 | # File: utils/helper.py 2 | 3 | def get_name(): 4 | return "Muhammad Hashim" 5 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/05_configuring_the_search_path/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | for path in sys.path: 4 | print(path) 5 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /assests/python-logo-white-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/assests/python-logo-white-bg.png -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/01_extend_module/common_utils/helper.py: -------------------------------------------------------------------------------- 1 | def get_name(): 2 | return "Muhammad Hashim" -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /02_object_oriented_programming/04_interfaces/06_Project_Video/readme.md: -------------------------------------------------------------------------------- 1 | # Project Video Platform 2 | 3 | We will start to decouple to avoid dependencies -------------------------------------------------------------------------------- /04_algorithms/07_searching/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/07_searching/images/01.jpg -------------------------------------------------------------------------------- /04_algorithms/07_searching/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/07_searching/images/02.jpg -------------------------------------------------------------------------------- /04_algorithms/07_searching/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/07_searching/images/03.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/06_sys_path/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # Print out each path in sys.path 4 | for path in sys.path: 5 | print(path) 6 | -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/02_data_hiding_in_modules/module.py: -------------------------------------------------------------------------------- 1 | # __all__ = ['a', '_b'] 2 | 3 | a = 10 4 | _b = 20 5 | c = 30 6 | d = 40 7 | 8 | -------------------------------------------------------------------------------- /01_python_fundamentals/24_modules_packages/01_package_import_basic/web_scraper/__init__.py: -------------------------------------------------------------------------------- 1 | from web_scraper.crawler import parse_page 2 | 3 | __all__ = ["parse_page"] -------------------------------------------------------------------------------- /02_object_oriented_programming/13_customizing_typechecker/mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | python_version = 3.12 3 | warn_return_any = True 4 | disallow_untyped_defs = True 5 | 6 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/01_import_and_attributes/main.py: -------------------------------------------------------------------------------- 1 | # File: main.py 2 | 3 | import b 4 | 5 | b.spam("Muhammad Hashim") 6 | print(b.version) # Outputs: 1.0 7 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/09_reloading_modules/changer.py: -------------------------------------------------------------------------------- 1 | # File: changer.py 2 | message = "After editing" 3 | 4 | def printer(): 5 | print("reloaded:", message) 6 | -------------------------------------------------------------------------------- /04_algorithms/01_introducing_algorithm/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/01_introducing_algorithm/images/01.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | __pycache__/ 4 | migrations/ 5 | *.bak 6 | *.dat 7 | *.dir 8 | .mypy_cache/ 9 | .pytest_cache/ 10 | envs/ 11 | db.sqlite3 12 | readme.txt -------------------------------------------------------------------------------- /02_object_oriented_programming/10_python_types/01_typing_system_in_python/script.js: -------------------------------------------------------------------------------- 1 | console.log([] + {}); // Output: "[object Object]" 2 | console.log({} + []); // Output: 0 3 | -------------------------------------------------------------------------------- /04_algorithms/02_analysis_of_an_algorithm/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/02_analysis_of_an_algorithm/images/01.jpg -------------------------------------------------------------------------------- /04_algorithms/02_analysis_of_an_algorithm/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/02_analysis_of_an_algorithm/images/02.jpg -------------------------------------------------------------------------------- /04_algorithms/02_analysis_of_an_algorithm/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/02_analysis_of_an_algorithm/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/01_array/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/01_array/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/11.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/12.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/13.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/14.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/15.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/16.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/17.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/18.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/images/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/02_binary_trees/images/19.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/08_module_namespace/module_example.py: -------------------------------------------------------------------------------- 1 | # module_example.py 2 | print("Module is loading...") 3 | x = 5 4 | y = [1, 2, 3] 5 | print("Module is ended.") 6 | 7 | -------------------------------------------------------------------------------- /01_python_fundamentals/08_delimiters/main.py: -------------------------------------------------------------------------------- 1 | # This is a comment 2 | 3 | text = "Hello, World!" # Double quotes for string 4 | path = 'C:\\Users\\Hashim\\Documents' # Escape character in string -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/01_stack/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/11.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/12.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/13.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/14.jpg -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/03_queues/images/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/03_stack_and_queues/03_queues/images/15.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/11.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/12.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/13.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/14.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/15.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/03_binary_search_tree/images/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/03_binary_search_tree/images/16.jpg -------------------------------------------------------------------------------- /03_data_structures/00_datatype_and_object_in_python/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/00_datatype_and_object_in_python/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/00_datatype_and_object_in_python/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/00_datatype_and_object_in_python/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/00_datatype_and_object_in_python/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/00_datatype_and_object_in_python/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/04_trees/01_terminology_of_trees/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/04_trees/01_terminology_of_trees/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/11.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/12.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/13.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/14.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/15.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/16.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/17.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/18.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/19.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/20.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/21.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/22.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/22.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/23.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/23.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/24.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/24.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/25.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/25.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/26.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/26.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/27.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/27.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/28.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/28.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/29.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/29.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/30.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/30.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/31.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/31.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/32.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/33.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/33.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/34.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/34.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/35.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/35.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/36.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/36.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/37.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/37.jpg -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/images/38.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/07_graphs_and_algorithms/graphs/images/38.jpg -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/05_event_loop/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | def get_loop(): 4 | loop = asyncio.get_event_loop() 5 | print(f"Event loop: {loop}") 6 | 7 | get_loop() 8 | -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/11.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/12.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/13.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/14.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/15.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/16.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/17.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/18.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/01_heaps/images/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/01_heaps/images/19.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/04_tokens/main.py: -------------------------------------------------------------------------------- 1 | # Incorrect: Python would parse 'ifx' as a single identifier 2 | ifx = 10 3 | 4 | # Correct: Adding whitespace to separate 'if' and 'x' 5 | # if x == 10: 6 | # print("x is 10") -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/01.png -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/11.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/12.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/13.jpg -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/06_hash_tables/01_Introducing_hash_tables/images/14.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/24_modules_packages/01_package_import_basic/web_scraper/crawler/page_parser.py: -------------------------------------------------------------------------------- 1 | # File: web_scraper/crawler/page_parser.py 2 | 3 | def parse_page(html): 4 | return f"Parsed content from: {html}" 5 | -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/04_mixed_usage_modes/main.py: -------------------------------------------------------------------------------- 1 | import greetings 2 | 3 | # Another script or interactive shell 4 | from calculator import add 5 | 6 | result = add(7, 3) 7 | print("7 + 3 =", result) 8 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CartConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'cart' 7 | -------------------------------------------------------------------------------- /01_python_fundamentals/21_working_with_files/logs.txt: -------------------------------------------------------------------------------- 1 | [2024-10-08 12:00:00] System started 2 | [2024-10-08 12:05:00] User logged in 3 | [2024-10-08 12:10:30] User accessed settings 4 | [2024-10-08 12:15:45] User logged out 5 | 6 | -------------------------------------------------------------------------------- /02_object_oriented_programming/13_customizing_typechecker/01_configuring_type_checker/main.py: -------------------------------------------------------------------------------- 1 | def add_numbers(a, b): 2 | return a + b 3 | 4 | result = add_numbers(5, 10) # Ab yeh sirf integers accept karega 5 | print(result) 6 | -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/02_priority_queues/images/00.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/02_priority_queues/images/00.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/02_priority_queues/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/02_priority_queues/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/02_priority_queues/images/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/05_heaps_and_periority_queues/02_priority_queues/images/03.png -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/03_byte_code/my_module.py: -------------------------------------------------------------------------------- 1 | # File: my_module.py 2 | 3 | def greet(name): 4 | print(f"Hello, {name}! Welcome to Python 3.12.") 5 | 6 | # Example usage (uncomment to test) 7 | # greet("Muhammad Hashim") 8 | -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/02_data_hiding_in_modules/main.py: -------------------------------------------------------------------------------- 1 | from module import * 2 | from underscore_example import * 3 | print(a, c) # Outputs: 1 3 4 | print(_b) # Raises NameError 5 | print(a) # Works 6 | # print(_b) -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/01_singly_linked_list/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/02.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/03.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/04.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/05.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/06.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/07.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/08.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/09.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/10.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/images/11.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/01_import_and_attributes/b.py: -------------------------------------------------------------------------------- 1 | # File: b.py 2 | import c 3 | 4 | 5 | version = "1.0" 6 | 7 | def spam(text): 8 | print(f"{text} spam") 9 | 10 | 11 | def spam(text): 12 | c.ham(text) 13 | -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/01.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/02.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/24_modules_packages/01_package_import_basic/web_scraper/utils/helper.py: -------------------------------------------------------------------------------- 1 | # File: web_scraper/utils/helper.py 2 | 3 | def clean_html(html): 4 | return html.strip() 5 | 6 | def format_url(url): 7 | return url.lower() 8 | -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/01.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/02.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/03.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/04.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/05.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/06.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/07.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/08.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/09.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/05_greedy_algorithm/images/10.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/02_recursion_algorithm/diagram/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/02_recursion_algorithm/diagram/01.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/02_recursion_algorithm/diagram/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/02_recursion_algorithm/diagram/02.png -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/01.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/02.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/03.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/03_divide_and_conquer/diagrams/04.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/mypackage/my_module.py: -------------------------------------------------------------------------------- 1 | # File: mypackage/my_module.py 2 | 3 | def greet(name): 4 | print(f"Hello, {name}! Welcome to Python modules.") 5 | 6 | def farewell(name): 7 | print(f"Goodbye, {name}! Happy coding.") 8 | -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/04_mixed_usage_modes/greetings.py: -------------------------------------------------------------------------------- 1 | # File: greetings.py 2 | 3 | def say_hello(): 4 | print("Hello, World!") 5 | 6 | if __name__ == "__main__": 7 | # This will only run if the script is executed directly 8 | say_hello() 9 | -------------------------------------------------------------------------------- /02_object_oriented_programming/14_defining_our_own_type/03_user_defined_classes/hashim_transcript.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/02_object_oriented_programming/14_defining_our_own_type/03_user_defined_classes/hashim_transcript.pdf -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_doubly/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_doubly/01.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_doubly/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_doubly/02.png -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_doubly/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_doubly/03.png -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/01.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/02.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/03.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/04.jpg -------------------------------------------------------------------------------- /03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/03_data_structures/02_linked_list/02_linked_list/03_circular_linked_list/images/circular_singly/05.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/01_extend_module/modules/main.py: -------------------------------------------------------------------------------- 1 | import user 2 | import sys 3 | 4 | for path in sys.path: 5 | print(path) 6 | 7 | 8 | import helper 9 | name = helper.get_name() 10 | myname = user.username(name) 11 | print(myname) -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/04_dynamic_programming_technique/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/04_dynamic_programming_technique/images/01.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/04_dynamic_programming_technique/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/04_dynamic_programming_technique/images/02.jpg -------------------------------------------------------------------------------- /04_algorithms/06_alogorithm_design_techniques_and_strategies/04_dynamic_programming_technique/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-Deep-Dive/HEAD/04_algorithms/06_alogorithm_design_techniques_and_strategies/04_dynamic_programming_technique/images/03.jpg -------------------------------------------------------------------------------- /01_python_fundamentals/24_modules_packages/01_package_import_basic/web_scraper/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # File: web_scraper/utils/__init__.py 2 | 3 | from .helper import clean_html, format_url 4 | 5 | __all__ = ["clean_html", "format_url"] # Defines what can be imported using 'from utils import *' 6 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/urls.py: -------------------------------------------------------------------------------- 1 | # urls.py 2 | from django.urls import path 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('', views.products_view, name='products'), 7 | path('calculate_total/', views.calculate_total, name='calculate_total'), 8 | ] 9 | -------------------------------------------------------------------------------- /01_python_fundamentals/13_iterations/main.py: -------------------------------------------------------------------------------- 1 | no = int(input("Please Enter Table no: ")) 2 | i = 1 3 | print(f'{no} x {i} = {no * i}') 4 | i += 1 5 | print(f'{no} x {i} = {no * i}') 6 | i += 1 7 | print(f'{no} x {i} = {no * i}') 8 | i += 1 9 | print(f'{no} x {i} = {no * i}') 10 | i += 1 11 | -------------------------------------------------------------------------------- /01_python_fundamentals/21_working_with_files/logs_backup.txt: -------------------------------------------------------------------------------- 1 | [2024-10-08 12:00:00] System started 2 | [2024-10-08 12:05:00] User logged in 3 | [2024-10-08 12:10:30] User accessed settings 4 | [2024-10-08 12:15:45] User logged out 5 | [2024-10-10 14:48:36] User logged in 6 | [2024-10-10 14:48:36] User updated settings 7 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/08_module_namespace/main.py: -------------------------------------------------------------------------------- 1 | import module2, module_example 2 | print(module2.name) # Outputs: Muhammad Hashim 3 | print(module2.age) # Outputs: 24 4 | 5 | print(dir(module2)) 6 | print(module2.__dict__.keys()) 7 | 8 | 9 | print(module_example.x) 10 | print(module_example.y) -------------------------------------------------------------------------------- /01_python_fundamentals/27_virtual_environment/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | django = "==5.2" 8 | asgiref = "*" 9 | sqlparse = "*" 10 | tzdata = "*" 11 | 12 | [dev-packages] 13 | 14 | [requires] 15 | python_version = "3.12" 16 | -------------------------------------------------------------------------------- /01_python_fundamentals/24_modules_packages/01_package_import_basic/web_scraper/crawler/__init__.py: -------------------------------------------------------------------------------- 1 | # File: web_scraper/crawler/__init__.py 2 | 3 | from .page_parser import parse_page 4 | 5 | 6 | __all__ = ["parse_page"] 7 | 8 | # Initialize any settings needed for the crawler package 9 | print("Crawler package loaded!") 10 | -------------------------------------------------------------------------------- /01_python_fundamentals/26_testing_your_code/name_function.py: -------------------------------------------------------------------------------- 1 | # name_function.py 2 | 3 | def get_formatted_name(first, last, middle=''): 4 | """Generate a neatly formatted full name.""" 5 | if middle: 6 | full_name = f"{first} {middle} {last}" 7 | else: 8 | full_name = f"{first} {last}" 9 | return full_name.title() -------------------------------------------------------------------------------- /01_python_fundamentals/22_scope/main.py: -------------------------------------------------------------------------------- 1 | import builtins 2 | 3 | # Safely using built-ins after overriding 4 | open = "Overridden Open" # Overrides the built-in open 5 | print(open) # Prints the string 6 | 7 | # Access the original built-in open 8 | with builtins.open("example.txt", "w") as file: 9 | file.write("This is safe!") 10 | -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/09_abstract_classes_and_methods/example.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | class MyABC(metaclass=ABCMeta): 4 | @abstractmethod 5 | def my_abstract_method(self): 6 | pass 7 | 8 | 9 | my = MyABC() # TypeError: Can't instantiate abstract class MyABC with abstract methods -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.2.py: -------------------------------------------------------------------------------- 1 | import re 2 | nonprintable_string = "\a\x1B\f\n\r\t\v" 3 | pattern = r"\a\x1B\f\n\r\t\v" 4 | if re.fullmatch(pattern, nonprintable_string): 5 | print("The text matches the pattern exactly! ✅") 6 | else: 7 | print("The text does not match the pattern. ❌") 8 | -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/08_polymorphism/data.csv: -------------------------------------------------------------------------------- 1 | name,age,city,hobbies,passion,career 2 | Muhammad Hashim,24,Islamabad,"Coffee, Mountain trips","Software Engineering","Python Instructor" 3 | Ibrahim,23,Islamabad,"Reading, Fitness","Finance","Financial Analyst" 4 | Hafiz,23,Lahore,"Gaming, Travel","Mechanical Engineering","Engineer" 5 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.6.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample text with bold tags 4 | text = "My cat is furry" 5 | 6 | # Regex pattern with lookbehind and lookahead 7 | regex_pattern = r"(?<=)\w+(?=)" 8 | 9 | # Find matches 10 | matches = re.findall(regex_pattern, text) 11 | print("Matches:", matches) -------------------------------------------------------------------------------- /02_object_oriented_programming/10_python_types/main.py: -------------------------------------------------------------------------------- 1 | from ctypes import string_at 2 | from sys import getsizeof 3 | from binascii import hexlify 4 | 5 | a = 0b01010000_01000001_01010100 # Binary number 6 | print(a) # Output: 5259604 7 | 8 | text = "PAT" 9 | print(string_at(id(text), getsizeof(text))) 10 | print(hexlify(string_at(id(text), getsizeof(text)))) 11 | -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/02_benefits_of_type_annotations/main.py: -------------------------------------------------------------------------------- 1 | # Function to double values and add to the list 2 | def add_doubled_values(my_list: list[int]) -> None: 3 | my_list.update([x * 2 for x in my_list]) # Correct method: extend 4 | 5 | # Function call 6 | numbers = [1, 2, 3] 7 | add_doubled_values(numbers) 8 | print(numbers) # Output: [1, 2, 3, 2, 4, 6] 9 | -------------------------------------------------------------------------------- /02_object_oriented_programming/14_defining_our_own_type/02_advance_anums/main.py: -------------------------------------------------------------------------------- 1 | from enum import Enum, auto 2 | 3 | class MotherSauce(Enum): 4 | BECHAMEL = auto() 5 | VELOUTE = auto() 6 | ESPAGNOLE = auto() 7 | TOMATO = auto() 8 | HOLLANDAISE = auto() 9 | # Intentional alias 10 | BECHAMEL_ALIAS = BECHAMEL 11 | 12 | # Usage 13 | print(list(MotherSauce)) 14 | -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/04_optional_type/failure.py: -------------------------------------------------------------------------------- 1 | def get_user_age(name): 2 | user_data = database_lookup(name) 3 | return user_data.age # What if user_data is None? 4 | 5 | 6 | def database_lookup(name): 7 | return None # Simulate a database lookup failure 8 | 9 | 10 | get_user_age("Alice") # AttributeError: 'NoneType' object has no attribute 'age' -------------------------------------------------------------------------------- /01_python_fundamentals/25_advance_module/04_mixed_usage_modes/calculator.py: -------------------------------------------------------------------------------- 1 | # File: calculator.py 2 | 3 | def add(a, b): 4 | return a + b 5 | 6 | def subtract(a, b): 7 | return a - b 8 | 9 | if __name__ == "__main__": 10 | # Run tests when executed directly 11 | print("Testing calculator functions:") 12 | print("3 + 5 =", add(3, 5)) 13 | print("10 - 4 =", subtract(10, 4)) 14 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/02_creating_a_class/main.py: -------------------------------------------------------------------------------- 1 | class TextBox: 2 | def __init__(self): 3 | self.text = "" 4 | 5 | def set_text(self, text): 6 | self.text = text 7 | 8 | def clear(self): 9 | self.text = "" 10 | 11 | textbox = TextBox() 12 | textbox.set_text("Hello, Python!") 13 | print(textbox.text) 14 | textbox.clear() 15 | print(textbox.text) -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/06_literals/main.py: -------------------------------------------------------------------------------- 1 | from typing import Literal 2 | def process_payment(method: Literal["Credit Card", "PayPal", "Crypto"]) -> str: 3 | return f"Processing {method} payment." 4 | 5 | # Valid Examples 6 | print(process_payment("Credit Card")) # ✅ 7 | print(process_payment("PayPal")) # ✅ 8 | 9 | # Invalid Example 10 | print(process_payment("Cash")) # ❌ Type error 11 | -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/01_extend_module/modules/user.py: -------------------------------------------------------------------------------- 1 | user_data = 'User Details' 2 | 3 | def get_user_info(**user_data): 4 | return f''' 5 | User name is {user_data['name']} 6 | User age is {user_data['age']} 7 | User profession is {user_data['profession']} 8 | User hobbies are {', '.join(user_data['hobbies'])} 9 | ''' 10 | 11 | def username(name): 12 | return f'User name is {name}' -------------------------------------------------------------------------------- /01_python_fundamentals/05_identifiers/main.py: -------------------------------------------------------------------------------- 1 | my_variable = 10 # Valid identifier 2 | MyVariable = 20 # Another valid identifier (different from the first due to case sensitivity) 3 | # 1stVariable = 30 # Invalid identifier (cannot start with a digit) 4 | नंबर१ = 5 5 | نمبر۲ = 10 6 | # Perform addition 7 | result = नंबर१ + نمبر۲ 8 | print(result) # In Python v3, Unicode characters classified as digits or combining marks are also allowed. 9 | 10 | -------------------------------------------------------------------------------- /01_python_fundamentals/26_testing_your_code/name.py: -------------------------------------------------------------------------------- 1 | from name_function import get_formatted_name 2 | 3 | print("Enter 'q' at any time to quit.") 4 | 5 | while True: 6 | first = input("\nPlease give me a first name: ") 7 | if first == 'q': 8 | break 9 | last = input("Please give me a last name: ") 10 | if last == 'q': 11 | break 12 | 13 | formatted_name = get_formatted_name(first, last) 14 | print(f"\tNeatly formatted name: {formatted_name}.") -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.4.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Example text with numbers and letters 4 | text = "123abc 456" 5 | 6 | # Greedy quantifier example 7 | regex_greedy = r'\b\d+\b' 8 | matches_greedy = re.findall(regex_greedy, text) 9 | print("Greedy Matches:", matches_greedy) 10 | 11 | # Lazy quantifier example 12 | regex_lazy = r'\b\d+?\b' 13 | matches_lazy = re.findall(regex_lazy, text) 14 | print("Lazy Matches:", matches_lazy) -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/02_composition_over_inheritance_principle/composition.py: -------------------------------------------------------------------------------- 1 | class Engine: 2 | def start(self) -> None: 3 | print("Engine started") 4 | 5 | class Car: 6 | def __init__(self) -> None: 7 | self.engine: Engine = Engine() 8 | 9 | def start(self) -> None: 10 | self.engine.start() 11 | print("Car started") 12 | 13 | if __name__ == "__main__": 14 | my_car: Car = Car() 15 | my_car.start() 16 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.0.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Regex to match "magical" dates in yyyy-mm-dd format 4 | regex_magical_date = r'\b\d\d(\d\d)-\1-\1\b' 5 | 6 | # Example text containing dates 7 | text_dates = "Here are some dates: 2008-08-08, 1999-12-12, 2024-09-12, and 2011-11-11, 2010-10-10." 8 | 9 | # Find all magical dates 10 | matches_magical_dates = re.findall(regex_magical_date, text_dates) 11 | print("Magical Dates:", matches_magical_dates) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.1.py: -------------------------------------------------------------------------------- 1 | import re 2 | text_to_match = """The punctuation characters in the ASCII table are: !"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~.""" 3 | pattern = r"The punctuation characters in the ASCII table are: !\"#\$%&'\(\)\*\+,-\./:;<=>\?@\[\\\]\^_`\{\|}~\." 4 | if re.fullmatch(pattern, text_to_match): 5 | print("The text matches the pattern exactly! ✅") 6 | else: 7 | print("The text does not match the pattern. ❌") 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/05_encapsulation/main.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self): 3 | self.base_salary = 0 4 | self.hourly_rate = 0 5 | 6 | def calculate_wage(self, extra_hours): 7 | return self.base_salary + (self.hourly_rate * extra_hours) 8 | 9 | 10 | if __name__ == "__main__": 11 | employee = Employee() 12 | employee.base_salary = 50000 13 | employee.hourly_rate = 20 14 | wage = employee.calculate_wage(20) 15 | print(wage) 16 | -------------------------------------------------------------------------------- /01_python_fundamentals/27_virtual_environment/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "django-project" 3 | version = "0.1.0" 4 | description = "Poetry For Django" 5 | authors = [ 6 | {name = "Muhammad Hashim",email = "hashiimtahir@gmail.com"} 7 | ] 8 | license = {text = "MIT"} 9 | readme = "README.md" 10 | requires-python = ">=3.12" 11 | dependencies = [ 12 | "django (>=5.2,<6.0)" 13 | ] 14 | 15 | 16 | [build-system] 17 | requires = ["poetry-core>=2.0.0,<3.0.0"] 18 | build-backend = "poetry.core.masonry.api" 19 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/04_procedural_programming/main.py: -------------------------------------------------------------------------------- 1 | def create_employee(base_salary, hourly_rate): 2 | return { 3 | "base_salary": base_salary, 4 | "hourly_rate": hourly_rate 5 | } 6 | 7 | def calculate_wage(employee, extra_hours): 8 | return employee["base_salary"] + (employee["hourly_rate"] * extra_hours) 9 | 10 | if __name__ == "__main__": 11 | employee = create_employee(50000, 20) 12 | wage = calculate_wage(employee, 20) 13 | print(wage) 14 | 15 | 16 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/ecommerce/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for ecommerce project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/ecommerce/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for ecommerce project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.3.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Correct regex to match text between

and

tags 4 | regex_lazy = r'

.*?

' 5 | 6 | text = """ 7 |

8 | The very first task is to find the beginning of a paragraph. 9 |

10 |

11 | Then you have to find the end of the paragraph 12 |

13 | """ 14 | 15 | # Find all matches for text between

and

tags 16 | matches = re.findall(regex_lazy, text, re.DOTALL) 17 | print("Matched Paragraphs:", matches) -------------------------------------------------------------------------------- /01_python_fundamentals/26_testing_your_code/test_name_function.py: -------------------------------------------------------------------------------- 1 | from name_function import get_formatted_name 2 | 3 | def test_first_last_name(): 4 | """Do names like 'muhammad hashim' work?""" 5 | formatted_name = get_formatted_name('muhammad', 'hashim') 6 | assert formatted_name == 'Muhammad Hashim' 7 | 8 | def test_first_last_middle_name(): 9 | """Do names like 'Wolfgang Amadeus Mozart' work?""" 10 | formatted_name = get_formatted_name('wolfgang', 'mozart', 'amadeus') 11 | assert formatted_name == 'Wolfgang Amadeus Mozart' -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/05_union_type/main.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | def parse_user_input(value: str) -> int | str: 4 | if value.isdigit(): 5 | return int(value) 6 | return value 7 | 8 | result1: Union[int, str] = parse_user_input("hello") 9 | print(f'Result1 type is {type(result1)} and its value is {result1}') # Output: "hello" (as a str) 10 | result2: Union[int, str] = parse_user_input("42") 11 | print(f'Result2 type is {type(result2)} and its value is {result2}') # Output: "hello" (as a str) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem3.0.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample text where we want to wrap matches in tags 4 | text = "Visit example.com for more info." 5 | 6 | # Regex pattern to match words (simple example) 7 | regex_pattern = r"\b\w+\b" 8 | 9 | # Replacement text: wrap the entire match (group 0) with an tag 10 | replacement_text = r'\g<0>' 11 | 12 | # Perform search-and-replace 13 | result = re.sub(regex_pattern, replacement_text, text) 14 | 15 | print("Result after replacement:", result) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem3.1.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample text containing a 10-digit number 4 | text = "My number is 1234567890, please call me!" 5 | 6 | # Regex pattern to match a 10-digit phone number 7 | regex_pattern = r"\b(\d{3})(\d{3})(\d{4})\b" 8 | 9 | # Replacement pattern to format the matched phone number 10 | replacement_text = r"(\1) \2-\3" 11 | 12 | # Perform search-and-replace using re.sub() 13 | formatted_text = re.sub(regex_pattern, replacement_text, text) 14 | 15 | print("Formatted text:", formatted_text) -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/09_final/main.py: -------------------------------------------------------------------------------- 1 | from typing import Final, Tuple 2 | 3 | DB_HOST: Final = "localhost" 4 | 5 | 6 | 7 | def connect_to_test_database(): 8 | global DB_HOST 9 | DB_HOST = "test-db.example.com" # Accidentally reassigning DB_HOST for a test database 10 | # Proceed with test connection... 11 | 12 | # CONFIG: Final[Tuple[str, str]] = ("debug_mode_off", "version_1.0") 13 | 14 | # Attempting to change CONFIG or its content will raise an error with `mypy` 15 | # CONFIG[0] = "debug_mode_on" # Type error: Tuples are immutable -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/04_optional_type/main.py: -------------------------------------------------------------------------------- 1 | def parse_integer(s: str) -> int | None: 2 | try: 3 | return int(s) 4 | except ValueError: 5 | return None 6 | 7 | def process_number(s: str) -> None: 8 | number = parse_integer(s) 9 | if number is not None: 10 | print(f"The number multiplied by 2 is {number * 2}") 11 | else: 12 | print(f"Invalid integer: '{s}'") 13 | 14 | if __name__ == "__main__": 15 | process_number("42") # Valid integer 16 | process_number("not a number") # Invalid integer -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.9.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample text to perform search-and-replace 4 | text = "This is a test: 123-456." 5 | 6 | # Regex pattern to match any three-digit number 7 | regex_pattern = r"\d{3}" 8 | 9 | # Replacement text: insert literal text including backreferences 10 | replacement_text = r"$%\*$1\\1" 11 | 12 | # Perform search-and-replace 13 | # `re.sub` is used to substitute matches with replacement text 14 | result = re.sub(regex_pattern, replacement_text, text) 15 | 16 | print("Result after replacement:", result) -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/08_async_generators/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | async def get_user_info(user_id): 4 | await asyncio.sleep(1) # Simulate API call delay 5 | return {"id": user_id, "name": f"User{user_id}"} 6 | 7 | async def user_info_generator(user_ids): 8 | for uid in user_ids: 9 | user_info = await get_user_info(uid) 10 | yield user_info 11 | 12 | async def main(): 13 | user_ids = [101, 102, 103] 14 | async for user in user_info_generator(user_ids): 15 | print(f"👤 Retrieved User: {user}") 16 | 17 | asyncio.run(main()) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.5.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample HTML text where there is content after but before 4 | text = """ 5 | 6 | 7 | Some content here. 8 | 9 |
10 | More content without closing the HTML tag. 11 | """ 12 | 13 | # Updated regex with atomic grouping to prevent runaway repetition 14 | regex_atomic = r'(?>.*?).*?' 15 | 16 | # Try to find matches 17 | matches_atomic = re.findall(regex_atomic, text, re.DOTALL) 18 | print("Matches with Atomic Grouping:", matches_atomic) 19 | -------------------------------------------------------------------------------- /02_object_oriented_programming/04_interfaces/01_tightly_coupled_code/main.py: -------------------------------------------------------------------------------- 1 | class TaxCalculator: 2 | def __init__(self, taxable_income: float): 3 | self.__taxable_income = taxable_income 4 | 5 | def calculate_tax(self) -> float: 6 | return self.__taxable_income * 0.3 7 | 8 | class TaxReport: 9 | def __init__(self): 10 | self.__calculator = TaxCalculator(1000000) 11 | 12 | def show(self): 13 | tax = self.__calculator.calculate_tax() 14 | print(tax) 15 | 16 | # Create an instance of TaxReport and show the tax 17 | report = TaxReport() 18 | report.show() 19 | -------------------------------------------------------------------------------- /01_python_fundamentals/24_modules_packages/01_package_import_basic/main.py: -------------------------------------------------------------------------------- 1 | # File: web_scraper/main.py 2 | 3 | from web_scraper import * 4 | from web_scraper.utils import clean_html, format_url 5 | 6 | # Example usage 7 | html = " Welcome to my site! " 8 | cleaned_html = clean_html(html) 9 | print(cleaned_html) # Outputs: Welcome to my site! 10 | 11 | formatted_url = format_url("HTTP://EXAMPLE.COM") 12 | print(formatted_url) # Outputs: http://example.com 13 | 14 | parsed_content = parse_page(cleaned_html) 15 | print(parsed_content) # Outputs: Parsed content from: Welcome to my site! 16 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.7.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample list of comma-separated words 4 | text = "one,two,three,one,two" 5 | 6 | # Regex pattern with conditionals to ensure each word appears at least once 7 | regex_pattern = r'\b(?:(?:(one)|(two)|(three))(?:,|\b)){3,}(?(1)|(?!))(?(2)|(?!))(?(3)|(?!))' 8 | 9 | # Test for matches 10 | match = re.match(regex_pattern, text) 11 | 12 | # Check if the pattern matched the text 13 | if match: 14 | print("Valid match: All three words are present at least once.") 15 | else: 16 | print("Invalid match: Not all three words are present.") -------------------------------------------------------------------------------- /02_object_oriented_programming/14_defining_our_own_type/10_decorator/main.py: -------------------------------------------------------------------------------- 1 | import functools 2 | import time 3 | 4 | def timer(func): 5 | @functools.wraps(func) 6 | def wrapper(*args, **kwargs): 7 | start_time = time.time() 8 | print(f"⏳ Starting '{func.__name__}'") 9 | result = func(*args, **kwargs) 10 | end_time = time.time() 11 | print(f"⏱️ '{func.__name__}' finished in {end_time - start_time:.4f} seconds") 12 | return result 13 | return wrapper 14 | 15 | @timer 16 | def compute_squares(n): 17 | return [i**2 for i in range(n)] 18 | 19 | # Usage 20 | compute_squares(1000000) 21 | -------------------------------------------------------------------------------- /01_python_fundamentals/02_lines_and_indentation/main.py: -------------------------------------------------------------------------------- 1 | x = 10 # This is a comment 2 | y = 20 # Python will ignore everything after the hash sign 3 | 4 | 5 | # Using a backslash to continue the statement 6 | total = 1 + 2 + 3 + \ 7 | 4 + 5 + 6 8 | 9 | # Using parentheses to continue the statement 10 | total = (1 + 2 + 3 + 11 | 4 + 5 + 6) 12 | 13 | 14 | text = """This is a long string 15 | that spans multiple lines.""" 16 | 17 | 18 | if x > 0: 19 | print("Positive number") 20 | y = x 21 | else: 22 | print("Non-positive number") 23 | y = 0 24 | 25 | def greet(name): 26 | print(f"Hello, {name}!") # Correct: 4 spaces for indentation 27 | -------------------------------------------------------------------------------- /01_python_fundamentals/09_literals/main.py: -------------------------------------------------------------------------------- 1 | 42 # Integer literal 2 | 3.14 # Floating-point literal 3 | 1.0j # Imaginary literal 4 | 5 | 6 | 'hello' # Single-quoted string literal 7 | "world" # Double-quoted string literal 8 | """Good 9 | night""" # Triple-quoted string literal (spans multiple lines) 10 | 11 | 12 | [42, 3.14, 'hello'] # List 13 | [] # Empty list 14 | 100, 200, 300 # Tuple 15 | () # Empty tuple 16 | {'x':42, 'y':3.14} # Dictionary 17 | {} # Empty dictionary 18 | {1, 2, 4, 8, 'string'} # Set 19 | 20 | 21 | empty_set = set() # Correct way to create an empty set -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.6.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Regex to match "cat" as a whole word 4 | regex_whole_word_cat = r'\bcat\b' 5 | 6 | # Example usage 7 | text = "My cat is brown. A category is different from a cat." 8 | matches = re.findall(regex_whole_word_cat, text) 9 | print(matches) # Output: ['cat', 'cat'] 10 | 11 | 12 | 13 | # Regex to match "cat" only if it is part of another word 14 | regex_non_whole_word_cat = r'\Bcat\B' 15 | 16 | # Example usage 17 | text = "My cat is brown. staccato is a word, and so is bobcat." 18 | matches = re.findall(regex_non_whole_word_cat, text) 19 | print(matches) # Output: ['cat', 'cat'] -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/01_encapsulate_principle/encapsulate.py: -------------------------------------------------------------------------------- 1 | class PaymentBase: 2 | def __init__(self, amount: int) -> None: 3 | self.amount: int = amount 4 | 5 | def process_payment(self) -> None: 6 | pass 7 | 8 | class CreditCard(PaymentBase): 9 | def process_payment(self) -> None: 10 | print(f"Credit card payment: {self.amount}") 11 | 12 | class PayPal(PaymentBase): 13 | def process_payment(self) -> None: 14 | print(f"PayPal payment: {self.amount}") 15 | 16 | 17 | if __name__ == "__main__": 18 | payments: list[PaymentBase] = [CreditCard(100), PayPal(200)] 19 | for payment in payments: 20 | payment.process_payment() 21 | -------------------------------------------------------------------------------- /01_python_fundamentals/26_testing_your_code/survey_program.py: -------------------------------------------------------------------------------- 1 | # survey_program.py 2 | 3 | from survey import AnonymousSurvey 4 | 5 | # Define a question, and make a survey. 6 | question = "What language did you first learn to speak?" 7 | language_survey = AnonymousSurvey(question) 8 | 9 | # Show the question, and store responses to the question. 10 | language_survey.show_question() 11 | print("Enter 'q' at any time to quit.\n") 12 | 13 | while True: 14 | response = input("Language: ") 15 | if response == 'q': 16 | break 17 | language_survey.store_response(response) 18 | 19 | # Show the survey results. 20 | print("\nThank you to everyone who participated in the survey!") 21 | language_survey.show_results() -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/09_async_comprehensions/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | async def fetch_user_profile(user_id): 4 | await asyncio.sleep(0.2) # Simulate API call delay 5 | return {"id": user_id, "name": f"User{user_id}"} 6 | 7 | async def user_id_generator(): 8 | for uid in range(1, 6): 9 | await asyncio.sleep(0.1) # Simulate data source delay 10 | yield uid 11 | 12 | async def main(): 13 | # Async List Comprehension to fetch user profiles 14 | user_profiles = [await fetch_user_profile(uid) async for uid in user_id_generator()] 15 | print("👥 User Profiles:") 16 | for profile in user_profiles: 17 | print(profile) 18 | 19 | asyncio.run(main()) -------------------------------------------------------------------------------- /03_data_structures/06_hash_tables/01_Introducing_hash_tables/main.py: -------------------------------------------------------------------------------- 1 | # my_dict = {"Hashim": "9229012345", "Muhammad": "9229012346", "Ishaque": 2 | # "9229012347", "Sara": "9229012348"} 3 | 4 | # print("Print All Keys and values") 5 | # for x, y in my_dict.items(): 6 | # print(f"{x}: {y}") 7 | # print(my_dict["Hashim"]) 8 | 9 | # print(sum(map(ord,"Hashim"))) 10 | 11 | def my_hash(s): 12 | mult = 1 13 | hv = 0 14 | for ch in s: 15 | hv += ord(ch) * mult 16 | mult += 1 17 | return hv 18 | 19 | for item in ('hello world', 'world hello', 'gello xorld'): 20 | print(f'{item}: {my_hash(item)}') 21 | 22 | for item in ('ad', 'ga'): 23 | print("{}: {}".format(item, my_hash(item))) 24 | -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/03_interface_not_implemented_principle/interfaces_bis.py: -------------------------------------------------------------------------------- 1 | from typing import Protocol 2 | 3 | class Logger(Protocol): 4 | def log(self, message: str) -> None: 5 | ... 6 | 7 | class ConsoleLogger: 8 | def log(self, message: str) -> None: 9 | print(f"Console: {message}") 10 | 11 | class FileLogger: 12 | def log(self, message: str) -> None: 13 | with open("log.txt", "a") as f: 14 | f.write(f"File: {message}\n") 15 | 16 | def log_message(logger: Logger, message: str) -> None: 17 | logger.log(message) 18 | 19 | 20 | if __name__ == "__main__": 21 | log_message(ConsoleLogger(), "A console log.") 22 | log_message(FileLogger(), "A file log.") 23 | -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/03_liskov_substitution_principle/main.py: -------------------------------------------------------------------------------- 1 | class Bird: 2 | def move(self) -> None: 3 | print("I'm moving") 4 | 5 | class FlyingBird(Bird): 6 | def move(self) -> None: 7 | print("I'm flying") 8 | 9 | class FlightlessBird(Bird): 10 | def move(self) -> None: 11 | print("I'm walking") 12 | 13 | def make_bird_move(bird: Bird) -> None: 14 | bird.move() 15 | 16 | if __name__ == "__main__": 17 | generic_bird: Bird = Bird() 18 | eagle: FlyingBird = FlyingBird() 19 | penguin: FlightlessBird = FlightlessBird() 20 | 21 | make_bird_move(generic_bird) # Output: I'm moving 22 | make_bird_move(eagle) # Output: I'm flying 23 | make_bird_move(penguin) # Output: I'm walking 24 | -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/04_coroutine/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | async def fetch_data(source, delay): 4 | print(f"Fetching data from {source}") 5 | await asyncio.sleep(delay) # Simulate I/O operation 6 | data = f"Data from {source}" 7 | print(f"Finished fetching from {source}") 8 | return data 9 | 10 | async def main(): 11 | # Schedule both fetch_data coroutines concurrently 12 | task1 = asyncio.create_task(fetch_data("Source 1", 2)) 13 | task2 = asyncio.create_task(fetch_data("Source 2", 3)) 14 | 15 | # Await both tasks to complete 16 | results = await asyncio.gather(task1, task2) 17 | 18 | print("Results:") 19 | for result in results: 20 | print(result) 21 | 22 | asyncio.run(main()) 23 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/views.py: -------------------------------------------------------------------------------- 1 | # views.py 2 | from django.shortcuts import render 3 | from django.http import JsonResponse 4 | 5 | # Sample products 6 | PRODUCTS = [ 7 | {'id': 1, 'name': 'Product A', 'price': 150}, 8 | {'id': 2, 'name': 'Product B', 'price': 250}, 9 | {'id': 3, 'name': 'Product C', 'price': 100}, 10 | ] 11 | 12 | def products_view(request): 13 | return render(request, 'product.html', {'products': PRODUCTS}) 14 | 15 | def calculate_total(request): 16 | # Receive selected product IDs and calculate the total 17 | selected_ids = request.GET.getlist('selected_ids[]') 18 | total = sum((lambda p: p['price'])(p) for p in PRODUCTS if str(p['id']) in selected_ids) 19 | return JsonResponse({'total': total}) 20 | -------------------------------------------------------------------------------- /02_object_oriented_programming/10_python_types/02_understanding_ducky_typing/main.py: -------------------------------------------------------------------------------- 1 | from typing import Iterable 2 | def print_items(items: Iterable): 3 | for item in items: 4 | print(item) 5 | print(" ",end='') 6 | 7 | print_items([1, 2, 3]) # List input 8 | print_items({4, 5, 6}) # Set input 9 | print_items({"A": 1, "B": 2}) # Dictionary input 10 | 11 | # This will raise an error because an integer is not iterable. 12 | # print_items(5) 13 | # Output: TypeError: 'int' object is not iterable 14 | 15 | def double_value(value): 16 | return value + value 17 | 18 | print(double_value(5)) # Output: 10 19 | print(double_value("abc")) # Output: abcabc 20 | print(double_value([1, 2, 3])) # Output: [1, 2, 3, 1, 2, 3] 21 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/07_abstraction/02_coupling/main.py: -------------------------------------------------------------------------------- 1 | class Browser: 2 | def navigate(self, address): 3 | ip = self.__find_ip_address(address) 4 | html = self.__send_http_request(ip) 5 | print(html) 6 | 7 | def __send_http_request(self, ip): 8 | if ip is not None: 9 | return "" 10 | else: 11 | return "No IP address or domain found" 12 | 13 | def __find_ip_address(self, address): 14 | if address: 15 | return address 16 | else: 17 | # return '127.0.0.1' 18 | return None 19 | 20 | browser = Browser() 21 | browser.navigate('127.0.0.0') 22 | browser.navigate(None) 23 | 24 | 25 | # A = ' ' 26 | # print(ord(A)) 27 | 28 | 29 | -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/02_async_walk/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import time 3 | from concurrent.futures import ProcessPoolExecutor 4 | 5 | def cpu_bound_task(): 6 | # CPU-bound operation ko simulate karte hain 7 | sum(i * i for i in range(10 ** 7)) 8 | print(f"{time.ctime()} CPU-bound task completed") 9 | 10 | async def main(): 11 | print(f"{time.ctime()} Main coroutine started") 12 | loop = asyncio.get_running_loop() 13 | 14 | # ProcessPoolExecutor create karna 15 | with ProcessPoolExecutor() as executor: 16 | await loop.run_in_executor(executor, cpu_bound_task) 17 | 18 | print(f"{time.ctime()} Main coroutine completed") 19 | 20 | if __name__ == "__main__": 21 | # Event loop ko run karna 22 | asyncio.run(main()) 23 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.8.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Regex to match "Muhammad", "Hashim", or "Ali" 4 | regex_names = r'Muhammad|Hashim|Ali' 5 | 6 | # Example text 7 | text = "Muhammad, Hashim, and Ali went to Muhammad's house." 8 | 9 | # Find all matches 10 | matches = re.findall(regex_names, text) 11 | print(matches) # Output: ['Muhammad', 'Hashim', 'Ali', 'Muhammad'] 12 | 13 | 14 | # Regex to match whole words "Muhammad", "Hashim", or "Ali" 15 | regex_names_whole = r'\bMuhammad\b|\bHashim\b|\bAli\b' 16 | 17 | # Example text 18 | text = "Muhammad, Hashim, and Ali went to Muhammad's house." 19 | 20 | # Find all matches 21 | matches = re.findall(regex_names_whole, text) 22 | print(matches) # Output: ['Muhammad', 'Hashim', 'Ali', 'Muhammad'] -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/08_polymorphism/data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Muhammad Hashim", 4 | "age": 24, 5 | "city": "Islamabad", 6 | "hobbies": ["Coffee", "Mountain trips"], 7 | "passion": "Software Engineering", 8 | "career": "Python Instructor" 9 | }, 10 | { 11 | "name": "Ibrahim", 12 | "age": 23, 13 | "city": "Islamabad", 14 | "hobbies": ["Reading", "Fitness"], 15 | "passion": "Finance", 16 | "career": "Financial Analyst" 17 | }, 18 | { 19 | "name": "Hafiz", 20 | "age": 23, 21 | "city": "Lahore", 22 | "hobbies": ["Gaming", "Travel"], 23 | "passion": "Mechanical Engineering", 24 | "career": "Engineer" 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/07_annotated/main.py: -------------------------------------------------------------------------------- 1 | from typing import Annotated 2 | 3 | class StringLength: 4 | def __init__(self, min_len: int, max_len: int): 5 | self.min_len = min_len 6 | self.max_len = max_len 7 | 8 | username: Annotated[str, StringLength(5, 15)] = "Hi" # Invalid, too short 9 | 10 | def validate_annotated(var, metadata) -> None: 11 | if isinstance(metadata, StringLength): 12 | if not (metadata.min_len <= len(var) <= metadata.max_len): 13 | raise ValueError(f"Length of '{var}' is not between {metadata.min_len} and {metadata.max_len}.") 14 | 15 | # Validation 16 | try: 17 | validate_annotated(username, StringLength(5, 15)) 18 | print(f"'{username}' is valid!") 19 | except ValueError as e: 20 | print(e) 21 | -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/03_interface_not_implemented_principle/interfaces.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | 4 | class Logger(ABC): 5 | @abstractmethod 6 | def log(self, message: str) -> None: 7 | pass 8 | 9 | 10 | class ConsoleLogger(Logger): 11 | def log(self, message: str) -> None: 12 | print(f"Console: {message}") 13 | 14 | 15 | class FileLogger(Logger): 16 | def log(self, message: str) -> None: 17 | with open("log.txt", "a") as f: 18 | f.write(f"File: {message}\n") 19 | 20 | 21 | def log_message(logger: Logger, message: str) -> None: 22 | logger.log(message) 23 | 24 | if __name__ == "__main__": 25 | log_message(ConsoleLogger(), "A console log.") 26 | log_message(FileLogger(), "A file log.") 27 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/01_single_responsible_principle/main.py: -------------------------------------------------------------------------------- 1 | class Report: 2 | def __init__(self, content: str) -> None: 3 | self.content: str = content 4 | 5 | def generate(self) -> None: 6 | print(f"Report content: {self.content}") 7 | 8 | class ReportSaver: 9 | def __init__(self, report: Report) -> None: 10 | self.report: Report = report 11 | 12 | def save_to_file(self, filename: str) -> None: 13 | with open(filename, "w") as file: 14 | file.write(self.report.content) 15 | 16 | if __name__ == "__main__": 17 | report_content: str = "This is the content." 18 | report: Report = Report(report_content) 19 | report.generate() 20 | 21 | report_saver: ReportSaver = ReportSaver(report) 22 | report_saver.save_to_file("report.txt") 23 | -------------------------------------------------------------------------------- /01_python_fundamentals/26_testing_your_code/survey.py: -------------------------------------------------------------------------------- 1 | # survey.py 2 | 3 | class AnonymousSurvey: 4 | """Collect anonymous answers to a survey question.""" 5 | 6 | def __init__(self, question): 7 | """Store a question, and prepare to store responses.""" 8 | self.question = question 9 | self.responses = [] 10 | 11 | def show_question(self): 12 | """Show the survey question.""" 13 | print(self.question) 14 | 15 | def store_response(self, new_response): 16 | """Store a single response to the survey.""" 17 | self.responses.append(new_response) 18 | 19 | def show_results(self): 20 | """Show all the responses that have been given.""" 21 | print("Survey results:") 22 | for response in self.responses: 23 | print(f"- {response}") -------------------------------------------------------------------------------- /01_python_fundamentals/18_dict/exercise.md: -------------------------------------------------------------------------------- 1 | # 🎉Exercises 2 | 3 | 1. **Build a Custom User Profile**: 4 | Create a function that accepts a dictionary of user data and returns a formatted user profile using unpacking. 5 | 6 | 2. **Combine and Filter Dictionaries**: 7 | Write a program that merges two dictionaries and filters out key-value pairs based on a specific condition. 8 | 9 | 3. **Create a Frequency Dictionary**: 10 | Use dictionary comprehensions to count the frequency of each word in a given sentence. 11 | 12 | 4. **Nested Dictionary Manipulation**: 13 | Use dictionary comprehensions to flatten a nested dictionary structure. 14 | 15 | 5. **Advanced Dictionary Unpacking**: 16 | Create a function that merges multiple dictionaries using dictionary unpacking and handles conflicting keys by summing the values. 17 | 18 | -------------------------------------------------------------------------------- /05_design_patterns/03_creational_design_patterns/01_factory_design_pattern/factory_method.py: -------------------------------------------------------------------------------- 1 | # ch03/factory/factory_method.py 2 | 3 | from typing import Protocol 4 | from pathlib import Path 5 | import json 6 | import xml.etree.ElementTree as ET 7 | 8 | class DataExtractor(Protocol): 9 | @property 10 | def parsed_data(self): 11 | ... 12 | 13 | class JSONDataExtractor: 14 | def __init__(self, filepath: Path): 15 | self.data = {} 16 | with open(filepath) as f: 17 | self.data = json.load(f) 18 | 19 | @property 20 | def parsed_data(self): 21 | return self.data 22 | 23 | class XMLDataExtractor: 24 | def __init__(self, filepath: Path): 25 | self.tree = ET.parse(filepath) 26 | 27 | @property 28 | def parsed_data(self): 29 | return self.tree 30 | 31 | 32 | -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/01_encapsulate_principle/encapsulate_bis.py: -------------------------------------------------------------------------------- 1 | class Circle: 2 | def __init__(self, radius: int) -> None: 3 | self._radius: int = radius 4 | 5 | @property 6 | def radius(self) -> int: 7 | return self._radius 8 | 9 | @radius.setter 10 | def radius(self, value: int) -> None: 11 | if value < 0: 12 | raise ValueError("Radius cannot be negative!") 13 | self._radius = value 14 | 15 | 16 | if __name__ == "__main__": 17 | circle: Circle = Circle(10) 18 | print(f"Initial radius: {circle.radius}") 19 | circle.radius = 15 20 | print(f"New radius: {circle.radius}") 21 | 22 | try: 23 | circle.radius = -5 24 | except ValueError as e: 25 | print(e) 26 | print(f"Current radius: {circle.radius}") 27 | -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/05_dependency_inversion_principle/main.py: -------------------------------------------------------------------------------- 1 | from typing import Protocol 2 | 3 | class MessageSender(Protocol): 4 | def send(self, message: str) -> None: 5 | ... 6 | 7 | class Email: 8 | def send(self, message: str) -> None: 9 | print(f"Sending email: {message}") 10 | 11 | class Notification: 12 | def __init__(self, sender: MessageSender) -> None: 13 | self.sender: MessageSender = sender 14 | 15 | def send(self, message: str) -> None: 16 | self.sender.send(message) 17 | 18 | def send_notification(sender: MessageSender, message: str) -> None: 19 | notif = Notification(sender=sender) 20 | notif.send(message=message) 21 | 22 | if __name__ == "__main__": 23 | email_sender = Email() 24 | send_notification(sender=email_sender, message="This is the message.") 25 | -------------------------------------------------------------------------------- /01_python_fundamentals/11_variables_as_references/main.py: -------------------------------------------------------------------------------- 1 | x = 42 # x is a reference to an integer object 2 | x = "hello" # x is now a reference to a string object 3 | 4 | x = 10 # Binding: x is now a reference to the integer 10 5 | x = 20 # Rebinding: x is now a reference to the integer 20 6 | 7 | x = 10 # x is bound to the integer 10 8 | del x # x is unbound, and the name x no longer exists 9 | 10 | x = [1, 2, 3] # x is bound to a list object 11 | y = x # y is also bound to the same list object 12 | del x # x is unbound, but the list object still exists because y refers to 13 | 14 | global_var = "I am global" # Global variable 15 | 16 | def my_function(): 17 | local_var = "I am local" # Local variable 18 | print(local_var) 19 | 20 | my_function() # Outputs: I am local 21 | print(global_var) # Outputs: I am global -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/01_truth_about_threads/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import aiohttp 3 | 4 | async def download_file(session, url): 5 | print(f"Starting download from {url}") 6 | async with session.get(url) as response: 7 | content = await response.read() 8 | filename = url.split("/")[-1] 9 | with open(filename, 'wb') as f: 10 | f.write(content) 11 | print(f"Finished downloading {filename}") 12 | 13 | async def main(): 14 | urls = [ 15 | 'https://www.example.com/file1.txt', 16 | 'https://www.example.com/file2.txt', 17 | 'https://www.example.com/file3.txt', 18 | ] 19 | async with aiohttp.ClientSession() as session: 20 | tasks = [download_file(session, url) for url in urls] 21 | await asyncio.gather(*tasks) 22 | 23 | asyncio.run(main()) 24 | -------------------------------------------------------------------------------- /04_algorithms/07_searching/unordered_linear_search.py: -------------------------------------------------------------------------------- 1 | 2 | def search(unordered_list, term): 3 | for i, item in enumerate(unordered_list): 4 | if term == unordered_list[i]: 5 | return i 6 | return None 7 | 8 | 9 | 10 | list1 = [60, 1, 88, 10, 11, 600] 11 | 12 | search_term = 10 13 | index_position = search(list1, search_term) 14 | print(index_position) 15 | 16 | 17 | 18 | list2 = ['packt', 'publish', 'data'] 19 | search_term2 = 'data' 20 | index_position2 = search(list2, search_term2) 21 | print(index_position2) 22 | 23 | 24 | if index_position is None: 25 | print(f"{search_term} not found") 26 | else: 27 | print(f"{search_term} found at position {index_position}") 28 | 29 | if index_position2 is None: 30 | print(f"{search_term2} not found") 31 | else: 32 | print(f"{search_term2} found at position {index_position2}") -------------------------------------------------------------------------------- /02_object_oriented_programming/04_interfaces/02_creating_an_interface/main.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class TaxCalculator(ABC): 4 | @abstractmethod 5 | def calculate_tax(self) -> float: 6 | pass 7 | 8 | class TaxCalculator24(TaxCalculator): 9 | def __init__(self, taxable_income: float): 10 | self.taxable_income = taxable_income 11 | 12 | def calculate_tax(self) -> float: 13 | return self.taxable_income * 0.3 14 | 15 | class TaxReport: 16 | def __init__(self, calculator: TaxCalculator): 17 | self.calculator = calculator 18 | 19 | def show(self): 20 | tax = self.calculator.calculate_tax() 21 | print(f"The calculated tax is: {tax}") 22 | 23 | # Example usage: 24 | taxable_income = 1000000 25 | calculator = TaxCalculator24(taxable_income) 26 | report = TaxReport(calculator) 27 | report.show() 28 | -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/02_composition_over_inheritance_principle/computer_composition.py: -------------------------------------------------------------------------------- 1 | class CPU: 2 | def process(self) -> None: 3 | print("CPU is processing data.") 4 | 5 | class RAM: 6 | def load_data(self) -> None: 7 | print("RAM is loading data.") 8 | 9 | class Storage: 10 | def read_data(self) -> None: 11 | print("Storage is reading data.") 12 | 13 | class Computer: 14 | def __init__(self) -> None: 15 | self.cpu: CPU = CPU() 16 | self.ram: RAM = RAM() 17 | self.storage: Storage = Storage() 18 | 19 | def start(self) -> None: 20 | self.cpu.process() 21 | self.ram.load_data() 22 | self.storage.read_data() 23 | print("Computer has started successfully!") 24 | 25 | if __name__ == "__main__": 26 | my_computer: Computer = Computer() 27 | my_computer.start() -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/03_constructors_and_inheritance/main.py: -------------------------------------------------------------------------------- 1 | class UIControl: 2 | def __init__(self, is_enabled=True): 3 | self._is_enabled = is_enabled 4 | print('UIControl Constructor') 5 | 6 | def enable(self): 7 | self._is_enabled = True 8 | 9 | def disable(self): 10 | self._is_enabled = False 11 | 12 | def is_enabled(self): 13 | return self._is_enabled 14 | 15 | 16 | class TextBox(UIControl): 17 | def __init__(self): 18 | super().__init__(True) 19 | self._text = "" 20 | print('TextBox Constructor') 21 | 22 | def set_text(self, text): 23 | self._text = text 24 | 25 | def clear(self): 26 | self._text = "" 27 | 28 | 29 | # Creating an instance of TextBox 30 | control = TextBox() 31 | control.disable() 32 | print(control.is_enabled()) # This will print: False 33 | -------------------------------------------------------------------------------- /02_object_oriented_programming/04_interfaces/04_what_is_dependency_injection/01_constructor_injection/main.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class TaxCalculator(ABC): 4 | @abstractmethod 5 | def calculate_tax(self) -> float: 6 | pass 7 | 8 | class TaxCalculator24(TaxCalculator): 9 | def __init__(self, taxable_income: float): 10 | self.__taxable_income = taxable_income 11 | 12 | def calculate_tax(self) -> float: 13 | return self.__taxable_income * 0.3 14 | 15 | class TaxReport: 16 | def __init__(self, calculator: TaxCalculator24): 17 | self.__calculator = calculator 18 | 19 | def show(self): 20 | tax = self.__calculator.calculate_tax() 21 | print(tax) 22 | 23 | # Example usage 24 | if __name__ == "__main__": 25 | calculator = TaxCalculator24(100000) 26 | report = TaxReport(calculator) 27 | report.show() 28 | -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/07_async_iterators/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | class AsyncLineReader: 4 | def __init__(self, lines): 5 | self.lines = lines 6 | self.index = 0 7 | 8 | def __aiter__(self): 9 | return self 10 | 11 | async def __anext__(self): 12 | if self.index >= len(self.lines): 13 | raise StopAsyncIteration 14 | await asyncio.sleep(0.5) # Simulate asynchronous I/O operation 15 | line = self.lines[self.index] 16 | self.index += 1 17 | return line 18 | 19 | async def main(): 20 | lines = [ 21 | "🌟 Line 1: Hello, Async World!", 22 | "🚀 Line 2: Asyncio makes concurrency easy.", 23 | "🔍 Line 3: Iterators can be asynchronous." 24 | ] 25 | 26 | async for line in AsyncLineReader(lines): 27 | print(f"📄 Read: {line}") 28 | 29 | asyncio.run(main()) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.8.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Regular expression with comments using free-spacing mode 4 | regex_pattern = r''' 5 | \d{4} # Year (four digits) 6 | - # Separator (hyphen) 7 | \d{2} # Month (two digits) 8 | - # Separator (hyphen) 9 | \d{2} # Day (two digits) 10 | ''' 11 | 12 | # Sample text 13 | text = "The date is 2024-08-19." 14 | 15 | # Finding matches with re.VERBOSE to allow comments and spaces 16 | matches = re.findall(regex_pattern, text, re.VERBOSE) 17 | print("Matches:", matches) 18 | 19 | 20 | import re 21 | 22 | # Regular expression with inline comments 23 | regex_pattern = r'(?#Year)\d{4}-(?#Separator)\d{2}-(?#Day)\d{2}' 24 | 25 | # Sample text 26 | text = "The date is 2024-08-19." 27 | 28 | # Finding matches without re.VERBOSE 29 | matches = re.findall(regex_pattern, text) 30 | print("Matches with inline comments:", matches) -------------------------------------------------------------------------------- /01_python_fundamentals/23_modules/04_module_search_path/main.py: -------------------------------------------------------------------------------- 1 | # File: main.py 2 | 3 | import sys 4 | import os 5 | 6 | # Get the current directory (where main.py is located) 7 | current_dir = os.path.dirname(os.path.abspath(__file__)) 8 | 9 | # Get the parent directory (up one level) 10 | parent_dir = os.path.dirname(os.path.dirname(current_dir)) 11 | 12 | # Construct the path to 'common_utils' 13 | common_utils_path = os.path.join(parent_dir, 'common_utils') 14 | 15 | # Add 'common_utils' to sys.path if it's not already there 16 | if common_utils_path not in sys.path: 17 | sys.path.append(common_utils_path) 18 | 19 | # Now we can import modules from 'common_utils' 20 | from mypackage import my_module 21 | import helper # Importing from 'common_utils' directory 22 | 23 | def main(): 24 | name = helper.get_name() 25 | my_module.greet(name) 26 | my_module.farewell(name) 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /01_python_fundamentals/26_testing_your_code/test_survey.py: -------------------------------------------------------------------------------- 1 | # test_survey.py 2 | 3 | import pytest 4 | from survey import AnonymousSurvey 5 | 6 | @pytest.fixture 7 | def language_survey(): 8 | """A survey that will be available to all test functions.""" 9 | question = "What language did you first learn to speak?" 10 | return AnonymousSurvey(question) 11 | 12 | def test_store_single_response(language_survey): 13 | """Test that a single response is stored properly.""" 14 | language_survey.store_response('English') 15 | assert 'English' in language_survey.responses 16 | 17 | def test_store_three_responses(language_survey): 18 | """Test that three individual responses are stored properly.""" 19 | responses = ['English', 'Spanish', 'Mandarin'] 20 | for response in responses: 21 | language_survey.store_response(response) 22 | for response in responses: 23 | assert response in language_survey.responses -------------------------------------------------------------------------------- /04_algorithms/07_searching/search_ordered_list.py: -------------------------------------------------------------------------------- 1 | 2 | def search_ordered(ordered_list, term): 3 | ordered_list_size = len(ordered_list) 4 | for i in range(ordered_list_size): 5 | if term == ordered_list[i]: 6 | return i 7 | elif ordered_list[i] > term: 8 | return None 9 | 10 | return None 11 | 12 | 13 | 14 | list1 = [2, 3, 4, 6, 7] 15 | 16 | search_term = 6 17 | index_position1 = search_ordered(list1, search_term) 18 | 19 | if index_position1 is None: 20 | print(f"{search_term} not found") 21 | else: 22 | print(f"{search_term} found at position {index_position1}") 23 | 24 | 25 | list2 = ['book','data','packt', 'structure'] 26 | 27 | search_term2 = 'structure' 28 | index_position2 = search_ordered(list2, search_term2) 29 | 30 | 31 | if index_position2 is None: 32 | print(f"{search_term2} not found") 33 | else: 34 | print(f"{search_term2} found at position {index_position2}") -------------------------------------------------------------------------------- /02_object_oriented_programming/04_interfaces/04_what_is_dependency_injection/03_method_injection/main.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class TaxCalculator(ABC): 4 | @abstractmethod 5 | def calculate_tax(self) -> float: 6 | pass 7 | 8 | class TaxCalculator24(TaxCalculator): 9 | def __init__(self, taxable_income: float): 10 | self.__taxable_income = taxable_income 11 | 12 | def calculate_tax(self) -> float: 13 | return self.__taxable_income * 0.3 14 | 15 | class TaxCalculator23(TaxCalculator): 16 | def calculate_tax(self) -> float: 17 | return 0.0 18 | 19 | class TaxReport: 20 | def __init__(self): 21 | self.__calculator = None 22 | 23 | def show(self, calculator: TaxCalculator): 24 | tax = calculator.calculate_tax() 25 | print(tax) 26 | 27 | calculator = TaxCalculator24(100000) 28 | report = TaxReport() 29 | report.show(calculator) 30 | report.show(TaxCalculator23()) 31 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/ecommerce/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for ecommerce project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/5.1/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import path, include 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('', include('cart.urls')), 23 | ] 24 | -------------------------------------------------------------------------------- /05_design_patterns/01_foundation_design_principles/04_loose_coupling_principle/loose_coupling.py: -------------------------------------------------------------------------------- 1 | from typing import Protocol 2 | 3 | class Sender(Protocol): 4 | def send(self, message: str) -> None: 5 | ... 6 | 7 | class MessageService: 8 | def __init__(self, sender: Sender) -> None: 9 | self.sender: Sender = sender 10 | 11 | def send_message(self, message: str) -> None: 12 | self.sender.send(message) 13 | 14 | class EmailSender: 15 | def send(self, message: str) -> None: 16 | print(f"Sending email: {message}") 17 | 18 | class SMSSender: 19 | def send(self, message: str) -> None: 20 | print(f"Sending SMS: {message}") 21 | 22 | if __name__ == "__main__": 23 | email_service: MessageService = MessageService(EmailSender()) 24 | email_service.send_message("Hello via Email") 25 | 26 | sms_service: MessageService = MessageService(SMSSender()) 27 | sms_service.send_message("Hello via SMS") 28 | -------------------------------------------------------------------------------- /02_object_oriented_programming/14_defining_our_own_type/11_pydantic/main.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel, EmailStr, Field, validator 2 | 3 | class User(BaseModel): 4 | name: str = Field(..., min_length=1) 5 | email: EmailStr 6 | age: int = Field(..., ge=0, le=120) # age >= 0 and <= 120 7 | phone: str 8 | 9 | @validator('phone') 10 | def phone_must_be_digits(cls, v): 11 | if not v.isdigit(): 12 | raise ValueError('Phone number must contain only digits.') 13 | if len(v) != 10: 14 | raise ValueError('Phone number must be exactly 10 digits.') 15 | return v 16 | 17 | def main(): 18 | try: 19 | user = User( 20 | name="Ali Ahmed", 21 | email="ali@example.com", 22 | age=30, 23 | phone="1234567890" 24 | ) 25 | print(user) 26 | except ValidationError as e: 27 | print(e.json()) 28 | 29 | if __name__ == "__main__": 30 | main() -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/04_overriding_methods/main.py: -------------------------------------------------------------------------------- 1 | class UIControl: 2 | def __init__(self, is_enabled=True): 3 | self._is_enabled = is_enabled 4 | 5 | def __str__(self): 6 | return str(self.is_enabled()) 7 | 8 | def enable(self): 9 | self._is_enabled = True 10 | 11 | def disable(self): 12 | self._is_enabled = False 13 | 14 | def is_enabled(self): 15 | return self._is_enabled 16 | 17 | 18 | class TextBox(UIControl): 19 | def __init__(self): 20 | super().__init__(True) 21 | self.text = "" 22 | 23 | def __str__(self): 24 | return self.text 25 | 26 | def set_text(self, text): 27 | self.text = text 28 | 29 | def clear(self): 30 | self.text = "" 31 | 32 | 33 | # Creating an instance of TextBox and setting text 34 | control = UIControl() 35 | print(str(control)) 36 | textbox = TextBox() 37 | textbox.set_text("Muhammad Hashim") 38 | print(textbox) 39 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/static/styles.css: -------------------------------------------------------------------------------- 1 | /* styles.css */ 2 | body { 3 | font-family: Arial, sans-serif; 4 | background-color: #f4f4f4; 5 | margin: 0; 6 | padding: 0; 7 | } 8 | 9 | .container { 10 | width: 90%; 11 | max-width: 600px; 12 | margin: 50px auto; 13 | background: #fff; 14 | padding: 20px; 15 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 16 | border-radius: 10px; 17 | } 18 | 19 | h1 { 20 | color: #333; 21 | text-align: center; 22 | } 23 | 24 | .products, .cart { 25 | margin-top: 20px; 26 | } 27 | 28 | .product { 29 | display: flex; 30 | align-items: center; 31 | margin-bottom: 10px; 32 | } 33 | 34 | .product-checkbox { 35 | margin-right: 10px; 36 | } 37 | 38 | .cart { 39 | border-top: 1px solid #ddd; 40 | padding-top: 10px; 41 | text-align: center; 42 | } 43 | 44 | #total { 45 | font-weight: bold; 46 | font-size: 1.5em; 47 | color: #0b57d0; 48 | } 49 | -------------------------------------------------------------------------------- /01_python_fundamentals/17_set/exercise.md: -------------------------------------------------------------------------------- 1 | # 📋 Exercises: 2 | 3 | 1. **Remove Duplicates**: Given a list of numbers, remove all duplicates using a set. 4 | 2. **Set Union**: Create two sets of integers and find the union of the sets. 5 | 3. **Set Intersection**: Given two sets of strings, find their intersection. 6 | 4. **Set Difference**: Create two sets of integers and find the difference between the first set and the second set. 7 | 5. **Symmetric Difference**: Given two sets, find the symmetric difference between them. 8 | 6. **Check Subset**: Given two sets, check if one set is a subset of the other. 9 | 7. **Set Membership**: Write a program to check if an element exists in a set. 10 | 8. **Set Update**: Create a set and add multiple items to it using the `update()` method. 11 | 9. **Frozen Set**: Create a frozen set and try to add or remove elements from it. 12 | 10. **Remove Common Elements**: Given two sets, remove all elements from the first set that are also present in the second set. 13 | 14 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.4.py: -------------------------------------------------------------------------------- 1 | import re 2 | regex_any_char_except_linebreaks = r'.' 3 | text = "Hello! How are \nyou?" 4 | matches = re.findall(regex_any_char_except_linebreaks, text) 5 | print(matches) # Output: ['H', 'e', 'l', 'l', 'o', '!', ' ', 'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', '?'] 6 | 7 | 8 | regex_any_char_including_linebreaks = r'[\s\S]' 9 | text = "Hello!\nHow are you?" 10 | matches = re.findall(regex_any_char_including_linebreaks, text) 11 | print(matches) # Output: ['H', 'e', 'l', 'l', 'o', '!', '\n', 'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', '?'] 12 | 13 | 14 | # Regex with mode modifier to match any character, including line breaks 15 | regex_with_mode_modifier = r'(?s).' 16 | # Example usage 17 | text = "Hello!\nHow are you?" 18 | matches = re.findall(regex_with_mode_modifier, text) 19 | print(matches) # Output: ['H', 'e', 'l', 'l', 'o', '!', '\n', 'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', '?'] -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/breadth_first_search.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | graph = dict() 4 | graph['A'] = ['B','G','D'] 5 | graph['B'] = ['A', 'F', 'E'] 6 | graph['C'] = ['F', 'H'] 7 | graph['D'] = ['F', 'A'] 8 | graph['E'] = ['B', 'G'] 9 | graph['F'] = ['B', 'D', 'C'] 10 | graph['G'] = ['A', 'E'] 11 | graph['H'] = ['C'] 12 | 13 | def breadth_first_search(graph, root): 14 | visited_vertices = list() 15 | graph_queue = deque([root]) 16 | visited_vertices.append(root) 17 | node = root 18 | while len(graph_queue) > 0: 19 | node = graph_queue.popleft() 20 | adj_nodes = graph[node] 21 | remaining_elements = set(adj_nodes).difference(set(visited_vertices)) 22 | if len(remaining_elements) > 0: 23 | for elem in sorted(remaining_elements): 24 | visited_vertices.append(elem) 25 | graph_queue.append(elem) 26 | 27 | return visited_vertices 28 | 29 | 30 | print(breadth_first_search(graph, 'A')) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem3.2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Sample text where "Match" is the regex match 4 | text = "BeforeMatchAfter" 5 | 6 | # Regex pattern to capture the left context, the match, and the right context 7 | regex_pattern = r"(.*?)(Match)(.*)" 8 | 9 | # Replacement function to construct the desired replacement text 10 | def replacement_function(match): 11 | # Group 1: Left context (text before the match) 12 | left_context = match.group(1) 13 | # Group 2: The regex match (the word "Match") 14 | matched_text = match.group(2) 15 | # Group 3: Right context (text after the match) 16 | right_context = match.group(3) 17 | 18 | # Construct the replacement text: Left + Whole + Right 19 | return f"{left_context}{left_context}{matched_text}{right_context}{right_context}" 20 | 21 | # Perform the search-and-replace using re.sub() 22 | result = re.sub(regex_pattern, replacement_function, text) 23 | 24 | print("Result after replacement:", result) -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/02_open_closed_principle/main.py: -------------------------------------------------------------------------------- 1 | import math 2 | from typing import Protocol 3 | 4 | class Shape(Protocol): 5 | def area(self) -> float: 6 | ... 7 | 8 | class Rectangle: 9 | def __init__(self, width: float, height: float) -> None: 10 | self.width: float = width 11 | self.height: float = height 12 | 13 | def area(self) -> float: 14 | return self.width * self.height 15 | 16 | class Circle: 17 | def __init__(self, radius: float) -> None: 18 | self.radius: float = radius 19 | 20 | def area(self) -> float: 21 | return math.pi * (self.radius ** 2) 22 | 23 | def calculate_area(shape: Shape) -> float: 24 | return shape.area() 25 | 26 | if __name__ == "__main__": 27 | rect: Rectangle = Rectangle(12, 8) 28 | rect_area: float = calculate_area(rect) 29 | print(f"Rectangle area: {rect_area}") 30 | 31 | circ: Circle = Circle(6.5) 32 | circ_area: float = calculate_area(circ) 33 | print(f"Circle area: {circ_area:.2f}") -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/01_type_annotations/main.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | import random 3 | 4 | def schedule_restaurant_open(open_time: datetime, workers_needed: int) -> None: 5 | available_workers: list[Worker] = find_workers_available_for_time(open_time) 6 | if len(available_workers) < workers_needed: 7 | print("Not enough workers available.") 8 | else: 9 | # Use random.sample to pick the required number of workers 10 | for worker in random.sample(available_workers, workers_needed): 11 | worker.schedule(open_time) 12 | 13 | class Worker: 14 | def __init__(self, name: str): 15 | self.name = name 16 | 17 | def schedule(self, time: datetime) -> None: 18 | print(f"Worker {self.name} scheduled at {time}.") 19 | 20 | def find_workers_available_for_time(open_time: datetime) -> list[Worker]: 21 | return [Worker("Alice"), Worker("Bob"), Worker("Charlie")] 22 | 23 | # Call the function 24 | schedule_restaurant_open(datetime(2024, 10, 9, 9, 0), 2) 25 | -------------------------------------------------------------------------------- /03_data_structures/04_trees/readme.md: -------------------------------------------------------------------------------- 1 | # **Trees in Data Structures** 🌳 2 | 3 | ## Introduction 📚 4 | 5 | A **tree** is a hierarchical, non-linear data structure. 6 | Unlike **lists**, **queues**, and **stacks** (which are linear and store items sequentially), a **tree** organizes data with a **parent-child relationship**. 7 | 8 | * The **top node** in a tree is called the **root node**. 9 | * The root node acts as the **ancestor** of all other nodes in the tree. 10 | 11 | ## Why Are Trees Important? 🚀 12 | 13 | **Tree data structures** are vital in computer science due to their use in: 14 | 15 | * Parsing expressions (e.g., arithmetic, logical) 16 | * Efficient searching (e.g., in databases, file systems) 17 | * Implementing **priority queues** 18 | * Representing structured documents (like **XML** and **HTML**) 19 | 20 | ## What You Will Learn 📝 21 | 22 | We will cover: 23 | 24 | * **Terms and definitions of trees** 25 | * **Binary trees** and **binary search trees** 26 | * **Tree traversal** techniques 27 | * **Binary search trees** in detail 28 | 29 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/01_what_is_classes/main.py: -------------------------------------------------------------------------------- 1 | class TextBox: 2 | def __init__(self): 3 | self.text = "" # Default text content is an empty string 4 | self.size = 0 # Default size is 0 5 | 6 | def set_text(self, text: str): 7 | """Sets the text content of the textbox.""" 8 | self.text = text 9 | 10 | def get_text(self) -> str: 11 | """Retrieves the current text content of the textbox.""" 12 | return self.text 13 | 14 | def set_size(self, size: int): 15 | """Sets the size of the textbox.""" 16 | self.size = size 17 | 18 | def get_size(self) -> int: 19 | """Retrieves the current size of the textbox.""" 20 | return self.size 21 | 22 | 23 | # Create an instance of the TextBox class 24 | textbox = TextBox() 25 | 26 | # Set text content 27 | textbox.set_text("Hello, World!") 28 | 29 | # Set size 30 | textbox.set_size(10) 31 | 32 | # Retrieve text content and size 33 | print("Text content:", textbox.get_text()) 34 | print("Size:", textbox.get_size()) -------------------------------------------------------------------------------- /02_object_oriented_programming/10_python_types/01_typing_system_in_python/main.py: -------------------------------------------------------------------------------- 1 | # Trying to add a list and a dictionary will raise an error. 2 | # print([] + {}) 3 | # Output: TypeError: can only concatenate list (not "dict") to list 4 | 5 | # def process_age(age): 6 | # return age + 1 7 | 8 | # Using a string accidentally 9 | # print(process_age("25")) 10 | # Output: TypeError: can only concatenate str (not "int") to str 11 | 12 | 13 | from typing import Union, List 14 | 15 | def parse_input(data: Union[str, List[int]]) -> List[str]: 16 | if isinstance(data, str): 17 | return data.split(',') 18 | elif isinstance(data, list): 19 | return [str(item) for item in data] 20 | else: 21 | raise ValueError("Unsupported data type!") 22 | 23 | # This function can handle both strings and lists 24 | print(parse_input("apple,banana,cherry")) # Output: ['apple', 'banana', 'cherry'] 25 | print(parse_input([1, 2, 3])) # Output: ['1', '2', '3'] 26 | print(parse_input(123)) # Output: ValueError: Unsupported data type! 27 | -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/graph.py: -------------------------------------------------------------------------------- 1 | 2 | # Adjancy List representation of a graph 3 | graph = dict() 4 | graph['A'] = ['B', 'C'] 5 | graph['B'] = ['E','C', 'A'] 6 | graph['C'] = ['A', 'B', 'E','F'] 7 | graph['E'] = ['B', 'C'] 8 | graph['F'] = ['C'] 9 | 10 | matrix_elements = sorted(graph.keys()) 11 | cols = rows = len(matrix_elements) 12 | 13 | print("Graph:", graph) 14 | print("Matrix Elements:", matrix_elements) 15 | print("Rows:", rows) 16 | print("Cols:", cols) 17 | 18 | adjacency_matrix = [[0 for x in range(rows)] for y in range(cols)] 19 | print("Adjacency Matrix:", adjacency_matrix) 20 | edges_list = [] 21 | 22 | for key in matrix_elements: 23 | for neighbor in graph[key]: 24 | edges_list.append((key, neighbor)) 25 | 26 | print("Edges List:", edges_list) 27 | 28 | for edge in edges_list: 29 | index_of_first_vertex = matrix_elements.index(edge[0]) 30 | index_of_second_vertex = matrix_elements.index(edge[1]) 31 | adjacency_matrix[index_of_first_vertex][index_of_second_vertex] = 1 32 | 33 | 34 | print(adjacency_matrix) 35 | 36 | -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/04_interface_segregation_principle/main.py: -------------------------------------------------------------------------------- 1 | from typing import Protocol 2 | 3 | class Printer(Protocol): 4 | def print_document(self) -> None: 5 | ... 6 | 7 | class Scanner(Protocol): 8 | def scan_document(self) -> None: 9 | ... 10 | 11 | class Fax(Protocol): 12 | def fax_document(self) -> None: 13 | ... 14 | 15 | class AllInOnePrinter: 16 | def print_document(self) -> None: 17 | print("Printing") 18 | 19 | def scan_document(self) -> None: 20 | print("Scanning") 21 | 22 | def fax_document(self) -> None: 23 | print("Faxing") 24 | 25 | class SimplePrinter: 26 | def print_document(self) -> None: 27 | print("Simply Printing") 28 | 29 | def do_the_print(printer: Printer) -> None: 30 | printer.print_document() 31 | 32 | if __name__ == "__main__": 33 | all_in_one = AllInOnePrinter() 34 | all_in_one.scan_document() 35 | all_in_one.fax_document() 36 | do_the_print(all_in_one) 37 | 38 | simple = SimplePrinter() 39 | do_the_print(simple) 40 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.9.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | regex_names = r'\b(Muhammad|Hashim|Ali)\b' 4 | text = "Muhammad, Hashim, and Ali went to Muhammad's house." 5 | matches = re.findall(regex_names, text) 6 | print(matches) # Output: ['Muhammad', 'Hashim', 'Ali', 'Muhammad'] 7 | 8 | # Regex to match and capture date parts in yyyy-mm-dd format 9 | regex_date = r'\b(\d{4})-(\d{2})-(\d{2})\b' 10 | regex_date_without_capture = r'\b(?:\d{4})-(?:\d{2})-(?:\d{2})\b' 11 | # Example text with today's date 12 | text = "The event is scheduled for 2024-09-12." 13 | 14 | # Find all matches with captured groups 15 | matches = re.findall(regex_date, text) 16 | print(matches) # Output: [('2024', '09', '12')] 17 | # Extracting year, month, and day from the first match 18 | if matches: 19 | year, month, day = matches[0] 20 | print(f"Year: {year}, Month: {month}, Day: {day}") 21 | # Output: Year: 2024, Month: 09, Day: 12 22 | 23 | matches = re.findall(regex_date_without_capture, text) 24 | print(matches) # Output: ['2024-09-12'] 25 | 26 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/07_abstraction/01_coupling/main.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self): 3 | self._base_salary = 0 4 | self._hourly_rate = 0 5 | 6 | def calculate_wage(self, extra_hours): 7 | return self._base_salary + (self._hourly_rate * extra_hours) 8 | 9 | def set_base_salary(self, base_salary): 10 | if base_salary <= 0: 11 | raise ValueError("Salary cannot be 0 or less.") 12 | self._base_salary = base_salary 13 | 14 | def __get_base_salary(self): 15 | return self._base_salary 16 | 17 | def __get_hourly_rate(self): 18 | return self._hourly_rate 19 | 20 | def set_hourly_rate(self, hourly_rate): 21 | if hourly_rate < 0: 22 | raise ValueError("Hourly rate cannot be negative.") 23 | self._hourly_rate = hourly_rate 24 | 25 | 26 | if __name__ == "__main__": 27 | employee = Employee() 28 | employee.set_base_salary(50000) 29 | employee.set_hourly_rate(20) 30 | wage = employee.calculate_wage(10) 31 | print(f'Calculate wages: {wage}') 32 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/06_getter_and_setter/main.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self, s, h): 3 | self.__salary = s 4 | self.__hours = h 5 | 6 | def calculate_wage(self, extra_hours): 7 | return f"The Calculated Wage is {self.__salary * self.__hours + 50 * extra_hours}" 8 | 9 | def set_salary(self, salary): 10 | if salary <= 0: 11 | raise ValueError("Salary can not less then or equal to zero") 12 | self.__salary = salary 13 | 14 | def get_salary(self): 15 | return self.__salary 16 | 17 | def set_hours(self, hours): 18 | if hours <= 0: 19 | raise ValueError("Hours can not less then or equal to zero") 20 | self.__hours = hours 21 | 22 | def get_hours(self): 23 | return self.__hours 24 | 25 | e = Employee(10000, 20) 26 | print(e.calculate_wage(10)) 27 | e.set_salary(2000000.124) 28 | e.set_hours(30) 29 | print(e.calculate_wage(10)) 30 | try: 31 | print(e.set_salary(0)) 32 | except ValueError as e: 33 | print("Salary can not less then or equal to zero") 34 | -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/array-base-stack.py: -------------------------------------------------------------------------------- 1 | size = 3 2 | data = [None] * size 3 | top = -1 4 | 5 | 6 | def push(value): 7 | global top 8 | if top >= size - 1: 9 | print("Stack overflow") 10 | else: 11 | top = top + 1 12 | data[top] = value 13 | 14 | def pop(): 15 | global top 16 | if top == -1: 17 | print("Stack Underflow") 18 | return None 19 | else: 20 | value = data[top] 21 | data[top] = None 22 | top -= 1 23 | return value 24 | 25 | def peek(): 26 | global top 27 | if top == -1: 28 | print("Stack is empty") 29 | return None 30 | else: 31 | return data[top] 32 | 33 | 34 | push('egg') 35 | push('ham') 36 | push('spam') 37 | 38 | print(data[0:top+1]) 39 | 40 | push('bacon') 41 | push('sausage') 42 | 43 | print(data[0:top+1]) 44 | 45 | print(pop()) 46 | print(data[0:top+1]) 47 | 48 | print(pop()) 49 | print(data[0:top+1]) 50 | 51 | print('Peek:', peek()) 52 | 53 | print(pop()) 54 | print(data[0:top+1]) 55 | 56 | print(pop()) 57 | print(data[0 : top + 1]) -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.1.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Regex to match dates and capture year, month, and day 4 | regex_named_date = r'\b(?P\d{4})-(?P\d{2})-(?P\d{2})\b' 5 | 6 | # Example text containing dates 7 | text_dates = "Here are some dates: 2024-09-12, 1999-12-25, 2008-08-08." 8 | 9 | # Find all matches and extract named groups 10 | matches_dates = re.finditer(regex_named_date, text_dates) 11 | for match in matches_dates: 12 | print(f"Year: {match.group('year')}, Month: {match.group('month')}, Day: {match.group('day')}") 13 | 14 | 15 | 16 | # Regex to match "magical" dates and capture the magical number 17 | regex_magical_named = r'\b\d{2}(?P\d{2})-(?P=magic)-(?P=magic)\b' 18 | 19 | # Example text containing dates 20 | text_magical_dates = "Some magical dates are: 2008-08-08, 2024-09-12, and 2011-11-11." 21 | 22 | # Find all matches and extract the "magic" number 23 | matches_magical = re.finditer(regex_magical_named, text_magical_dates) 24 | for match in matches_magical: 25 | print(f"Magical Number: {match.group('magic')}") -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/08_constructor/main.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self, base_salary, hourly_rate): 3 | self.__set_base_salary(base_salary) 4 | self.__set_hourly_rate(hourly_rate) 5 | 6 | def calculate_wage(self, extra_hours): 7 | return self.__base_salary + (self.__hourly_rate * extra_hours) 8 | 9 | def __set_base_salary(self, base_salary): 10 | if base_salary <= 0: 11 | raise ValueError("Salary cannot be 0 or less.") 12 | self.__base_salary = base_salary 13 | 14 | def __set_hourly_rate(self, hourly_rate): 15 | if hourly_rate < 0: 16 | raise ValueError("Hourly rate cannot be negative.") 17 | self.__hourly_rate = hourly_rate 18 | 19 | # Getter methods can be public if needed 20 | def get_base_salary(self): 21 | return self.__base_salary 22 | 23 | def get_hourly_rate(self): 24 | return self.__hourly_rate 25 | 26 | 27 | if __name__ == "__main__": 28 | employee = Employee(50000, 20) 29 | wage = employee.calculate_wage(10) 30 | print(f'Calculate wages: {wage}') -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/04_optional_type/user.py: -------------------------------------------------------------------------------- 1 | class UserData: 2 | def __init__(self, name: str, age: int): 3 | self.name = name 4 | self.age = age 5 | 6 | 7 | # Mock database as a dictionary 8 | database = { 9 | "Muhammad Hashim": UserData("Muhammad Hashim", 25), 10 | "Alice": UserData("Alice", 30), 11 | "Bob": UserData("Bob", 28), 12 | } 13 | 14 | def database_lookup(name: str) -> UserData | None: 15 | return database.get(name) 16 | 17 | 18 | def get_user_age(name: str) -> int | None: 19 | user_data = database_lookup(name) 20 | if user_data is not None: 21 | return user_data.age 22 | return None 23 | 24 | 25 | def display_user_age(name: str): 26 | age = get_user_age(name) 27 | if age is not None: 28 | print(f"{name} is {age} years old. 🎉") 29 | else: 30 | print(f"User '{name}' not found. 😢") 31 | 32 | 33 | def main(): 34 | display_user_age("Muhammad Hashim") 35 | display_user_age("Alice") 36 | display_user_age("Unknown User") 37 | 38 | if __name__ == "__main__": 39 | main() 40 | 41 | -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/readme.md: -------------------------------------------------------------------------------- 1 | # 📊 **Graphs and Algorithms** 2 | 3 | Graphs are a **non-linear data structure** in which the problem is represented as a **network** by connecting a set of **nodes** with **edges**. 4 | 5 | For example: 6 | 7 | * In a graph, **nodes** can represent **different cities**. 8 | * The **links (edges)** between them represent **connections** (like roads or flights). 9 | 10 | Graphs are one of the most important data structures because they are widely used to solve computing problems—especially when the problem involves **objects and their connections**, such as finding the **shortest path** between two cities. 11 | 12 | Graphs provide an efficient way to represent **real-world problems** as **network-like structures** for analysis and optimization. 13 | 14 | --- 15 | 16 | ## 📘 What You Will Learn in This section 17 | 18 | In this section, we will explore the following concepts: 19 | 20 | * 🧩 **The concept of the graph data structure** 21 | * 📝 **How to represent a graph and traverse it** 22 | * ⚙️ **Different operations and their implementation on graphs** 23 | 24 | -------------------------------------------------------------------------------- /02_object_oriented_programming/08_lambda_expression/cart/templates/product.html: -------------------------------------------------------------------------------- 1 | 2 | {% load static %} 3 | 4 | 5 | 6 | 7 | Shopping Cart 8 | 9 | 10 | 11 |
12 |

🛒 Product Selection

13 | 14 |
15 | {% for product in products %} 16 |
17 | 18 | {{ product.name }} - Rs. {{ product.price }} 19 |
20 | {% endfor %} 21 |
22 | 23 |
24 |

Cart Total

25 |

Total: Rs. 0

26 |
27 |
28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/08_polymorphism/data.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Muhammad Hashim 4 | 24 5 | Islamabad 6 | 7 | Coffee 8 | Mountain trips 9 | 10 | Software Engineering 11 | Python Instructor 12 | 13 | 14 | Ibrahim 15 | 23 16 | Islamabad 17 | 18 | Reading 19 | Fitness 20 | 21 | Finance 22 | Financial Analyst 23 | 24 | 25 | Hafiz 26 | 23 27 | Lahore 28 | 29 | Gaming 30 | Travel 31 | 32 | Mechanical Engineering 33 | Engineer 34 | 35 | 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Muhammad Hashim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /02_object_oriented_programming/04_interfaces/04_what_is_dependency_injection/02_setter_injection/main.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | 4 | class TaxCalculator(ABC): 5 | @abstractmethod 6 | def calculate_tax(self) -> float: 7 | pass 8 | 9 | 10 | class TaxCalculator24(TaxCalculator): 11 | def __init__(self, taxable_income: float): 12 | self.__taxable_income = taxable_income 13 | 14 | def calculate_tax(self) -> float: 15 | return self.__taxable_income * 0.3 16 | 17 | 18 | class TaxCalculator23(TaxCalculator): 19 | def calculate_tax(self) -> float: 20 | return 0.0 21 | 22 | 23 | class TaxReport: 24 | def __init__(self, calculator: TaxCalculator): 25 | self.__calculator = calculator 26 | 27 | def set_calculator(self, calculator: TaxCalculator): 28 | self.__calculator = calculator 29 | 30 | def show(self): 31 | tax = self.__calculator.calculate_tax() 32 | print(tax) 33 | 34 | 35 | calculator = TaxCalculator24(100000) 36 | report = TaxReport(calculator) 37 | report.show() 38 | 39 | report.set_calculator(TaxCalculator23()) 40 | report.show() 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.3.py: -------------------------------------------------------------------------------- 1 | import re 2 | calendar_regex = r'c[ae]l[ae]nd[ae]r' 3 | text = "calender, calandar, celendar, celandar, cielendar, cialendar cAlandAr" 4 | matches = re.findall(calendar_regex, text) 5 | print(matches) # Output: ['calender', 'calandar', 'celendar', 'celandar'] 6 | 7 | 8 | # Regex to match a single hexadecimal character 9 | hex_char_regex = r'[a-fA-F0-9]' 10 | # Example usage 11 | text = "1, A, g, 3F, Z" 12 | matches = re.findall(hex_char_regex, text) 13 | print(matches) # Output: ['1', 'A', '3', 'F'] 14 | 15 | 16 | # Regex to match a single non-hexadecimal character 17 | non_hex_char_regex = r'[^a-fA-F0-9]' 18 | # Example usage 19 | text = "1, A, g, 3F, Z, !" 20 | matches = re.findall(non_hex_char_regex, text) 21 | print(matches) # Output: [',', ' ', ',', ' ', 'g', ',', ' ', ',', ' ', 'Z', ',', ' ', '!'] 22 | 23 | 24 | # Case insensitive match for hexadecimal characters 25 | case_insensitive_hex_regex = r'(?i)[a-f0-9]' 26 | # Example usage 27 | text = "A, b, C, d, 3, F" 28 | matches = re.findall(case_insensitive_hex_regex, text) 29 | print(matches) # Output: ['A', 'b', 'C', 'd', '3', 'F'] -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/09_abstract_classes_and_methods/main.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class UIControl(ABC): 4 | def __init__(self): 5 | self._is_enabled = True 6 | 7 | @abstractmethod 8 | def render(self): 9 | pass 10 | 11 | def enable(self): 12 | self._is_enabled = True 13 | 14 | def disable(self): 15 | self._is_enabled = False 16 | 17 | def is_enabled(self): 18 | return self._is_enabled 19 | 20 | 21 | class TextBox(UIControl): 22 | def __init__(self): 23 | super().__init__() 24 | self._text = "" 25 | 26 | def render(self): 27 | print("Render TextBox") 28 | 29 | def __str__(self): 30 | return self._text 31 | 32 | def set_text(self, text): 33 | self._text = text 34 | 35 | def clear(self): 36 | self._text = "" 37 | 38 | 39 | class CheckBox(UIControl): 40 | def render(self): 41 | print("Render CheckBox") 42 | 43 | 44 | # Usage 45 | textbox = TextBox() 46 | checkbox = CheckBox() 47 | textbox.set_text("Muhammad Hashim") 48 | print(textbox) 49 | textbox.render() 50 | checkbox.render() 51 | -------------------------------------------------------------------------------- /03_data_structures/07_graphs_and_algorithms/graphs/depth-first-search.py: -------------------------------------------------------------------------------- 1 | graph = dict() 2 | graph['A'] = ['B', 'S'] 3 | graph['B'] = ['A'] 4 | graph['S'] = ['A','G','C'] 5 | graph['D'] = ['C'] 6 | graph['G'] = ['S','F','H'] 7 | graph['H'] = ['G','E'] 8 | graph['E'] = ['C','H'] 9 | graph['F'] = ['C','G'] 10 | graph['C'] = ['D','S','E','F'] 11 | 12 | def depth_first_search(graph, root): 13 | visited_vertices = list() 14 | graph_stack = list() 15 | 16 | graph_stack.append(root) 17 | node = root 18 | while graph_stack: 19 | if node not in visited_vertices: 20 | visited_vertices.append(node) 21 | adj_nodes = graph[node] 22 | if set(adj_nodes).issubset(set(visited_vertices)): 23 | graph_stack.pop() 24 | if len(graph_stack) > 0: 25 | node = graph_stack[-1] 26 | continue 27 | else: 28 | remaining_elements = set(adj_nodes).difference(set(visited_vertices)) 29 | first_adj_node = sorted(remaining_elements)[0] 30 | graph_stack.append(first_adj_node) 31 | node = first_adj_node 32 | return visited_vertices 33 | 34 | 35 | print(depth_first_search(graph, 'A')) -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/10_constructor_overloading/main.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | def __init__(self, base_salary, hourly_rate=None): 3 | self.__set_base_salary(base_salary) 4 | if hourly_rate is None: 5 | self.hourly_rate = 0 6 | else: 7 | self.__set_hourly_rate(hourly_rate) 8 | 9 | def calculate_wage(self, extra_hours=0): 10 | return self.base_salary + (self.hourly_rate * extra_hours) 11 | 12 | def __set_base_salary(self, base_salary): 13 | if base_salary < 0: 14 | raise ValueError("Salary cannot be less than 0.") 15 | self.base_salary = base_salary 16 | 17 | def __get_base_salary(self): 18 | return self.base_salary 19 | 20 | def __get_hourly_rate(self): 21 | return self.hourly_rate 22 | 23 | def __set_hourly_rate(self, hourly_rate): 24 | if hourly_rate < 0: 25 | raise ValueError("Hourly rate cannot be negative.") 26 | self.hourly_rate = hourly_rate 27 | 28 | 29 | 30 | employee1 = Employee(10000) 31 | employee2 = Employee(50000, 20) 32 | wage1 = employee1.calculate_wage() 33 | wage2 = employee2.calculate_wage() 34 | print(wage1) 35 | print(wage2) 36 | -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/readme.md: -------------------------------------------------------------------------------- 1 | # 🌳 **Heaps and Priority Queues** 2 | 3 | A **heap** is a **tree-based data structure** in which each **node** has a specific relationship with other nodes, and they are stored in a particular **order**. 4 | 5 | Depending on how nodes are arranged, heaps can be of two main types: 6 | 7 | * 🔽 **Min Heap** → The smallest element is always at the root. 8 | * 🔼 **Max Heap** → The largest element is always at the root. 9 | 10 | --- 11 | 12 | ## 🛠️ Priority Queue 13 | 14 | A **priority queue** is an important data structure that is similar to **queues** and **stacks**, but with a twist: 15 | 16 | 👉 It stores **data along with their priority**. 17 | 👉 Elements are served **based on priority** instead of arrival order. 18 | 19 | **Implementation options**: 20 | 21 | * 📦 Array 22 | * 🔗 Linked List 23 | * 🌲 Trees 24 | 25 | ⚡ But the **most efficient implementation** is using a **heap**. 26 | 27 | --- 28 | 29 | ## 📖 In this section, we will learn: 30 | 31 | 1. 🌳 The concept of the **heap data structure** and different **operations** on it. 32 | 2. 🎯 Understanding the concept of the **priority queue**. 33 | 3. 🐍 How to implement **priority queues in Python**. 34 | 35 | --- -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem2.2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Match a googol (100-digit number) 4 | regex_googol = r'\b\d{100}\b' 5 | 6 | text = "Number: 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890." 7 | 8 | matches = re.findall(regex_googol, text) 9 | print("Googol Matches:", matches) 10 | 11 | 12 | 13 | 14 | # Match a 32-bit hexadecimal number 15 | regex_hex = r'\b[a-f0-9]{1,8}\b' 16 | 17 | text = "Hex numbers: 1a2b, deadbeef, 01234567." 18 | 19 | matches = re.findall(regex_hex, text, re.IGNORECASE) 20 | print("Hexadecimal Matches:", matches) 21 | 22 | 23 | 24 | # Match a 32-bit hexadecimal number with optional 'h' 25 | regex_hex_suffix = r'\b[a-f0-9]{1,8}h?\b' 26 | 27 | text = "Hex numbers: 1a2bh, deadbeef, 01234567h." 28 | 29 | matches = re.findall(regex_hex_suffix, text, re.IGNORECASE) 30 | print("Hexadecimal Matches with 'h' suffix:", matches) 31 | 32 | 33 | # Match a floating-point number 34 | regex_float = r'\d*\.\d+(?:e\d+)?' 35 | 36 | text = "Floating-point numbers: 0.5, 1.23e10, .75." 37 | 38 | matches = re.findall(regex_float, text) 39 | print("Floating-Point Matches:", matches) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /05_design_patterns/02_solid_principles/readme.md: -------------------------------------------------------------------------------- 1 | # SOLID Design Principles 🚀 2 | 3 | In the world of software engineering, principles and best practices are essential for building a **robust**, **maintainable**, and **efficient** codebase. Among these, the **SOLID principles**, introduced by Robert C. Martin, are key to creating software that is **understandable**, **flexible**, and **maintainable**. 4 | 5 | ## 📚 Topics Covered 6 | 7 | ### 1️⃣ Single Responsibility Principle (SRP) 8 | - Ensures that a class or module has **one and only one reason to change**. 9 | 10 | ### 2️⃣ Open-Closed Principle (OCP) 11 | - Encourages designing software entities to be **open for extension but closed for modification**. 12 | 13 | ### 3️⃣ Liskov Substitution Principle (LSP) 14 | - Guarantees that derived classes can be **substituted** for their base classes without altering the behavior of the program. 15 | 16 | ### 4️⃣ Interface Segregation Principle (ISP) 17 | - Promotes the creation of **specific** interfaces rather than forcing classes to implement unnecessary methods. 18 | 19 | ### 5️⃣ Dependency Inversion Principle (DIP) 20 | - Advocates for the use of **abstractions** over concrete implementations to **reduce dependency** on low-level modules. 21 | -------------------------------------------------------------------------------- /01_python_fundamentals/12_decisions_statements/main.py: -------------------------------------------------------------------------------- 1 | age = 19 2 | if age >= 18: 3 | print("You are old enough to vote!") 4 | 5 | 6 | my_age = 17 7 | 8 | if my_age >= 18: 9 | print("You are old enough to vote!") 10 | else: 11 | print("Sorry, you are too young to vote.") 12 | 13 | 14 | 15 | our_age = 12 16 | 17 | if our_age < 4: 18 | print("Your admission cost is $0.") 19 | elif our_age < 18: 20 | print("Your admission cost is $25.") 21 | else: 22 | print("Your admission cost is $40.") 23 | 24 | 25 | 26 | marks = 85 27 | 28 | if marks >= 90: 29 | print("You got an A grade! 🎉") 30 | elif marks >= 75 and marks < 90: 31 | print("You got a B grade! 👍") 32 | elif marks >= 60 and marks < 75: 33 | print("You got a C grade! 👌") 34 | else: 35 | print("You need to improve. 📚") 36 | 37 | 38 | 39 | 40 | mood = "energetic" 41 | 42 | if mood == "happy": 43 | print("How about listening to some pop music? 🎤") 44 | elif mood == "sad": 45 | print("Try some blues to feel those emotions! 🎷") 46 | elif mood == "energetic": 47 | print("Rock music is your go-to! 🎸") 48 | elif mood == "relaxed": 49 | print("Smooth jazz will be perfect for you. 🎹") 50 | else: 51 | print("Discover some new indie tracks! 🎧") -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/postfix-expression-tree.py: -------------------------------------------------------------------------------- 1 | 2 | class Stack: 3 | def __init__(self): 4 | self.elements = [] 5 | 6 | def push(self, item): 7 | self.elements.append(item) 8 | 9 | def pop(self): 10 | return self.elements.pop() 11 | 12 | 13 | class TreeNode: 14 | def __init__(self, data=None): 15 | self.data = data 16 | self.right = None 17 | self.left = None 18 | 19 | def calc(node): 20 | if node.data == "+": 21 | return calc(node.left) + calc(node.right) 22 | elif node.data == "-": 23 | return calc(node.left) - calc(node.right) 24 | elif node.data == "*": 25 | return calc(node.left) * calc(node.right) 26 | elif node.data == "/": 27 | return calc(node.left) / calc(node.right) 28 | else: 29 | return node.data 30 | 31 | expr = "4 5 + 5 3 - *".split() 32 | # ['4', '5', '+', '5', '3', '-', '*'] 33 | stack = Stack() 34 | 35 | for term in expr: 36 | if term in "+-*/": 37 | node = TreeNode(term) 38 | node.right = stack.pop() 39 | node.left = stack.pop() 40 | else: 41 | node = TreeNode(int(term)) 42 | stack.push(node) 43 | 44 | root = stack.pop() 45 | result = calc(root) 46 | print(result) -------------------------------------------------------------------------------- /02_object_oriented_programming/12_collection_types/01_annotated_collections/main.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from typing import List, Dict 3 | 4 | @dataclass 5 | class Item: 6 | name: str # Name of the item (e.g., "Laptop") 7 | quantity: int # Quantity of the item ordered 8 | price_per_unit: float # Price per unit of the item 9 | 10 | discounts: Dict[str, float] = { 11 | "Laptop": 0.10, # 10% discount on Laptop 12 | "Keyboard": 0.05, # 5% discount on Keyboard 13 | } 14 | order_items = [ 15 | Item(name="Laptop", quantity=1, price_per_unit=1500.0), 16 | Item(name="Mouse", quantity=2, price_per_unit=25.0), 17 | Item(name="Keyboard", quantity=1, price_per_unit=75.0), 18 | ] 19 | 20 | 21 | def calculate_order_total_with_discounts(items: List[Item], discounts: Dict[str, float]) -> float: 22 | total = 0.0 23 | for item in items: 24 | discount = discounts.get(item.name, 0.0) # Default discount is 0 if not found 25 | total += item.quantity * item.price_per_unit * (1 - discount) 26 | return total 27 | 28 | 29 | total_price_with_discounts = calculate_order_total_with_discounts(order_items, discounts) 30 | print(f"Total Price with Discounts: ${total_price_with_discounts:.2f}") # Output: $1542.50 31 | 32 | -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/09_default_arguments/main.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | numberOfEmployees = 0 3 | 4 | def __init__(self, base_salary, hourly_rate=0): 5 | self.__set_base_salary(base_salary) 6 | self.__set_hourly_rate(hourly_rate) 7 | Employee.numberOfEmployees += 1 8 | 9 | def calculate_wage(self, extra_hours=0): 10 | return self.base_salary + (self.hourly_rate * extra_hours) 11 | 12 | @staticmethod 13 | def print_number_of_employees(): 14 | print(Employee.numberOfEmployees) 15 | 16 | def __set_base_salary(self, base_salary): 17 | if base_salary <= 0: 18 | raise ValueError("Salary cannot be 0 or less.") 19 | self.base_salary = base_salary 20 | 21 | def __get_base_salary(self): 22 | return self.base_salary 23 | 24 | def __get_hourly_rate(self): 25 | return self.hourly_rate 26 | 27 | def __set_hourly_rate(self, hourly_rate): 28 | if hourly_rate < 0: 29 | raise ValueError("Hourly rate cannot be negative.") 30 | self.hourly_rate = hourly_rate 31 | 32 | 33 | if __name__ == "__main__": 34 | employee = Employee(50000, 20) 35 | Employee.print_number_of_employees() 36 | wage = employee.calculate_wage() 37 | print(wage) 38 | 39 | -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/02_the_object_class/main.py: -------------------------------------------------------------------------------- 1 | class User(object): 2 | def __new__(cls, username, *args, **kwargs): 3 | # Ensure username is always stored in uppercase 4 | username = username.upper() # Convert to uppercase 5 | # Create the instance using the superclass's __new__ method 6 | instance = super().__new__(cls) 7 | # Store the converted username in the instance 8 | instance.username = username 9 | return instance 10 | 11 | def __init__(self, username): 12 | # Constructor will not modify username; __new__ handles it 13 | self.original_username = username # Just to store the original (if needed) 14 | 15 | def __str__(self): 16 | # Provide a friendly string representation of the object 17 | return f"User(username={self.username})" 18 | # Creating User objects with different username inputs 19 | user1 = User("hashim") 20 | user2 = User("ali") 21 | user3 = User("Fatima") 22 | 23 | # Displaying the users 24 | print(user1) # Output: User(username=HASHIM) 25 | print(user2) # Output: User(username=ALI) 26 | print(user3) # Output: User(username=FATIMA) 27 | 28 | # Accessing the username attribute 29 | print(user1.username) # Output: HASHIM 30 | print(user1.original_username) # Output: hashim -------------------------------------------------------------------------------- /03_data_structures/03_stack_and_queues/01_stack/linkedlist-base-stack.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self, data=None): 3 | self.next = None 4 | self.data = data 5 | 6 | 7 | class stack: 8 | def __init__(self): 9 | self.top = None 10 | self.size = 0 11 | 12 | def push(self, data): 13 | node = Node(data) 14 | if self.top: 15 | node.next = self.top 16 | self.top = node 17 | else: 18 | self.top = node 19 | self.size += 1 20 | 21 | def pop(self): 22 | if self.top: 23 | data = self.top.data 24 | self.size -= 1 25 | if self.top.next: 26 | self.top = self.top.next 27 | else: 28 | self.top = None 29 | return data 30 | else: 31 | print("Stack is already empty!") 32 | 33 | def peek(self): 34 | if self.top: 35 | return self.top.data 36 | else: 37 | print('Stack is empty!') 38 | 39 | 40 | words = stack() 41 | words.push('egg') 42 | words.push('ham') 43 | words.push('spam') 44 | 45 | words.pop() 46 | words.pop() 47 | words.pop() 48 | words.peek() 49 | words.pop() 50 | 51 | current = words.top 52 | while current: 53 | print(current.data) 54 | current = current.next 55 | 56 | -------------------------------------------------------------------------------- /02_object_oriented_programming/12_collection_types/03_typed_dict/main.py: -------------------------------------------------------------------------------- 1 | from typing import TypedDict, Optional, Union 2 | 3 | class Preferences(TypedDict): 4 | theme: str 5 | notifications: bool 6 | 7 | class UserProfile(TypedDict): 8 | username: str 9 | email: str 10 | age: int 11 | preferences: Preferences 12 | 13 | class ProfileUpdates(TypedDict, total=False): 14 | username: Optional[str] 15 | email: Optional[str] 16 | age: Optional[int] # Ensure `age` is expected to be an int 17 | preferences: Optional[Preferences] 18 | 19 | def update_user_profile(profile: UserProfile, updates: ProfileUpdates) -> UserProfile: 20 | for key, value in updates.items(): 21 | if key in profile: 22 | profile[key] = value 23 | else: 24 | raise KeyError(f"Invalid key: {key}") 25 | return profile 26 | 27 | # Correct Usage 28 | user_profile: UserProfile = { 29 | "username": "MuhammadHashim", 30 | "email": "hashim@example.com", 31 | "age": 24, 32 | "preferences": {"theme": "dark", "notifications": True} 33 | } 34 | 35 | # Now if "age" is a string, mypy will detect this as an error 36 | updates: ProfileUpdates = {"age": "twenty-five", "preferences": {"theme": "light", "notifications": False}} 37 | 38 | updated_profile = update_user_profile(user_profile, updates) 39 | print(updated_profile) 40 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.7.py: -------------------------------------------------------------------------------- 1 | import re as r 2 | import regex as re 3 | # Regex to find the trademark sign (™) 4 | regex_trademark = r'\u2122' 5 | 6 | text = "This is a trademark symbol ™ and here is another one: ™." 7 | matches = r.findall(regex_trademark, text) 8 | print(matches) # Output: ['™', '™'] 9 | 10 | regex_currency = r'\p{Sc}' 11 | text = "The price is $100 or €85 or ¥1000." 12 | matches = re.findall(regex_currency, text, re.UNICODE) 13 | print(matches) # Output: ['$', '€', '¥'] 14 | 15 | # Regex to match any character in the "Greek Extended" block 16 | regex_greek_extended = r'[\u1F00-\u1FFF]' 17 | 18 | text = "Greek letters: ἀ ἁ ἂ ἃ." 19 | matches = r.findall(regex_greek_extended, text) 20 | print(matches) # Output: ['ἀ', 'ἁ', 'ἂ', 'ἃ'] 21 | 22 | # Regex to match any character in the "Greek" script 23 | regex_greek_script = r'[\u0370-\u03FF]' 24 | 25 | text = "Greek letters: Α, Β, Γ, Δ, ε, ζ." 26 | matches = r.findall(regex_greek_script, text) 27 | print(matches) # Output: ['Α', 'Β', 'Γ', 'Δ', 'ε', 'ζ'] 28 | 29 | # Regex to match a grapheme (base character + combining marks) 30 | regex_grapheme = r'(\P{M}\p{M}*)' 31 | 32 | text = "à is a grapheme." 33 | matches = re.findall(regex_grapheme, text) 34 | print(matches) # Output: ['à', ' ', 'i', 's', ' ', 'a', ' ', 'g', 'r', 'a', 'p', 'h', 'e', 'm', 'e', '.'] 35 | 36 | -------------------------------------------------------------------------------- /03_data_structures/04_trees/02_binary_trees/prefix-expression-tree.py: -------------------------------------------------------------------------------- 1 | class Stack: 2 | def __init__(self): 3 | self.elements = [] 4 | def push(self, item): 5 | self.elements.append(item) 6 | def pop(self): 7 | return self.elements.pop() 8 | 9 | class TreeNode: 10 | def __init__(self, data=None): 11 | self.data = data 12 | self.left = None 13 | self.right = None 14 | 15 | def calc(node): 16 | if node.data == "+": 17 | return calc(node.left) + calc(node.right) 18 | elif node.data == "-": 19 | return calc(node.left) - calc(node.right) 20 | elif node.data == "*": 21 | return calc(node.left) * calc(node.right) 22 | elif node.data == "/": 23 | return calc(node.left) / calc(node.right) 24 | else: 25 | return node.data 26 | 27 | # ---------- PREFIX PARSING (Right-to-Left, using a stack) ---------- 28 | def build_tree_from_prefix(prefix_tokens): 29 | st = Stack() 30 | for tok in reversed(prefix_tokens): 31 | if tok in "+-*/": 32 | node = TreeNode(tok) 33 | left_child = st.pop() 34 | right_child = st.pop() 35 | node.left = left_child 36 | node.right = right_child 37 | st.push(node) 38 | else: 39 | st.push(TreeNode(int(tok))) 40 | return st.pop() 41 | 42 | # Example 43 | prefix_expr = "* + 4 5 - 5 3".split() 44 | root = build_tree_from_prefix(prefix_expr) 45 | print(calc(root)) # -> 18 -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/01_inheritance/main.py: -------------------------------------------------------------------------------- 1 | class UIControl: 2 | def __init__(self): 3 | self._is_enabled = True 4 | 5 | def enable(self): 6 | self._is_enabled = True 7 | print("Control enabled") 8 | 9 | def disable(self): 10 | self._is_enabled = False 11 | print("Control disabled") 12 | 13 | def get_is_enabled(self): 14 | return self._is_enabled 15 | 16 | 17 | class TextBox(UIControl): 18 | def __init__(self): 19 | super().__init__() 20 | self.text = "" 21 | 22 | def set_text(self, text): 23 | if self._is_enabled: 24 | self.text = text 25 | print(f"Text set to: {self.text}") 26 | else: 27 | print("Cannot set text, control is disabled") 28 | 29 | def get_text(self): 30 | return self.text 31 | 32 | def clear_text(self): 33 | if self._is_enabled: 34 | self.text = None 35 | print("Text cleared") 36 | else: 37 | print("Cannot clear text, control is disabled") 38 | 39 | 40 | textbox1 = TextBox() 41 | print(textbox1.get_is_enabled()) # True 42 | textbox1.disable() 43 | print(textbox1.get_is_enabled()) # True 44 | 45 | textbox1.set_text("Hello") # Cannot set text, control is disabled 46 | textbox1.enable() 47 | textbox1.set_text('Muhammad Hashim') 48 | print(textbox1.get_text()) # Muhammad Hashim 49 | textbox1.clear_text() 50 | print(textbox1.get_text()) # Muhammad Hashim 51 | -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/01_truth_about_threads/file1.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example Domain 5 | 6 | 7 | 8 | 9 | 36 | 37 | 38 | 39 |
40 |

Example Domain

41 |

This domain is for use in illustrative examples in documents. You may use this 42 | domain in literature without prior coordination or asking for permission.

43 |

More information...

44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/01_truth_about_threads/file2.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example Domain 5 | 6 | 7 | 8 | 9 | 36 | 37 | 38 | 39 |
40 |

Example Domain

41 |

This domain is for use in illustrative examples in documents. You may use this 42 | domain in literature without prior coordination or asking for permission.

43 |

More information...

44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /02_object_oriented_programming/15_async_programming/01_truth_about_threads/file3.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example Domain 5 | 6 | 7 | 8 | 9 | 36 | 37 | 38 | 39 |
40 |

Example Domain

41 |

This domain is for use in illustrative examples in documents. You may use this 42 | domain in literature without prior coordination or asking for permission.

43 |

More information...

44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/04_optional_type/pizza_making_with_return.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def cook_1(): 4 | """First cook: Prepares the pizza dough and adds sauce.""" 5 | steps = [] 6 | steps.append("🥖 Cook 1: Preparing the pizza dough...") 7 | time.sleep(1) # Simulating time delay 8 | steps.append("🍅 Cook 1: Adding tomato sauce...") 9 | time.sleep(1) 10 | return steps # Returning progress 11 | 12 | def cook_2(previous_steps): 13 | """Second cook: Adds toppings and preheats the oven.""" 14 | steps = previous_steps # Continuing from previous steps 15 | steps.append("🧀 Cook 2: Adding cheese and toppings...") 16 | time.sleep(1) 17 | steps.append("🔥 Cook 2: Preheating the oven...") 18 | time.sleep(1) 19 | return steps # Returning progress 20 | 21 | def cook_3(previous_steps): 22 | """Third cook: Bakes the pizza and serves it.""" 23 | steps = previous_steps # Continuing from previous steps 24 | steps.append("🍕 Cook 3: Placing the pizza in the oven...") 25 | time.sleep(1) 26 | steps.append("⏳ Cook 3: Waiting for the pizza to bake...") 27 | time.sleep(1) 28 | steps.append("✅ Cook 3: Pizza is ready to serve! 🍽️") 29 | return steps # Final result 30 | 31 | # Simulating the cooking process 32 | steps_1 = cook_1() # Cook 1 starts 33 | steps_2 = cook_2(steps_1) # Cook 2 continues 34 | final_steps = cook_3(steps_2) # Cook 3 finishes 35 | 36 | # Display the step-by-step process 37 | for step in final_steps: 38 | print(step) 39 | -------------------------------------------------------------------------------- /02_object_oriented_programming/02_inheritance/10_callable_object/main.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | 4 | class Shape(ABC): 5 | def __init__(self, name): 6 | self.name = name 7 | 8 | @abstractmethod 9 | def area(self): 10 | raise NotImplementedError("Subclasses must implement area() method") 11 | 12 | 13 | class Circle(Shape): 14 | def __init__(self, name, radius): 15 | super().__init__(name) 16 | self.radius = radius 17 | 18 | def area(self): 19 | return 3.14 * self.radius ** 2 20 | 21 | 22 | class Square(Shape): 23 | def __init__(self, name, side_length): 24 | super().__init__(name) 25 | self.side_length = side_length 26 | 27 | def area(self): 28 | return self.side_length ** 2 29 | 30 | 31 | class AreaCalculator: 32 | def __init__(self, shape): 33 | self.shape = shape 34 | 35 | def __call__(self): 36 | return self.shape.area() 37 | 38 | 39 | # Create instances of Circle and Square 40 | circle = Circle("Circle", 5) 41 | square = Square("Square", 4) 42 | 43 | # Create instances of AreaCalculator with Circle and Square objects 44 | circle_calculator = AreaCalculator(circle) 45 | square_calculator = AreaCalculator(square) 46 | 47 | # Call the instances of AreaCalculator as if they were functions to calculate the area 48 | circle_area = circle_calculator() 49 | square_area = square_calculator() 50 | 51 | # Output the results 52 | print("Area of", circle.name, ":", circle_area) 53 | print("Area of", square.name, ":", square_area) 54 | -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/02_priority_queues/priority-queue-heap.py: -------------------------------------------------------------------------------- 1 | class PriorityQueueHeap: 2 | def __init__(self): 3 | self.heap = [()] 4 | self.size = 0 5 | 6 | def arrange(self, i): 7 | while i // 2 > 0: 8 | if self.heap[i][0] < self.heap[i // 2][0]: 9 | self.heap[i], self.heap[i // 2] = self.heap[i // 2], self.heap[i] 10 | i //= 2 11 | 12 | def insert(self, priority, item): 13 | self.heap.append((priority, item)) 14 | self.size += 1 15 | self.arrange(self.size) 16 | 17 | def sink(self, i): 18 | while i * 2 <= self.size: 19 | mc = self.minchild(i) 20 | if self.heap[i][0] > self.heap[mc][0]: 21 | self.heap[i], self.heap[mc] = self.heap[mc], self.heap[i] 22 | i = mc 23 | 24 | def minchild(self, i): 25 | if i * 2 + 1 > self.size: 26 | return i * 2 27 | if self.heap[i * 2][0] < self.heap[i * 2 + 1][0]: 28 | return i * 2 29 | return i * 2 + 1 30 | 31 | def delete_at_root(self): 32 | item = self.heap[1][1] 33 | self.heap[1] = self.heap[self.size] 34 | self.size -= 1 35 | self.heap.pop() 36 | self.sink(1) 37 | return item 38 | 39 | 40 | h = PriorityQueueHeap() 41 | h.insert(2, "Bat") 42 | h.insert(13,"Cat") 43 | h.insert(18, "Rat") 44 | h.insert(26, "Ant") 45 | h.insert(3, "Lion") 46 | h.insert(4, "Bear") 47 | # h.heap 48 | 49 | 50 | for i in range(h.size): 51 | n = h.delete_at_root() 52 | print(n) 53 | print(h.heap) -------------------------------------------------------------------------------- /02_object_oriented_programming/12_collection_types/03_typed_dict/typedict.py: -------------------------------------------------------------------------------- 1 | from typing import TypedDict 2 | 3 | class Preferences(TypedDict): 4 | theme: str 5 | notifications: bool 6 | 7 | class UserProfile(TypedDict): 8 | username: str 9 | email: str 10 | age: int 11 | preferences: Preferences 12 | 13 | 14 | class ProfileUpdates(TypedDict, total=False): 15 | username: str | None 16 | email: str | None 17 | age: int | None 18 | preferences: Preferences | None 19 | 20 | 21 | def update_user_profile(profile: UserProfile, updates: ProfileUpdates) -> UserProfile: 22 | if "username" in updates and updates["username"] is not None: 23 | profile["username"] = updates["username"] 24 | if "email" in updates and updates["email"] is not None: 25 | profile["email"] = updates["email"] 26 | if "age" in updates and updates["age"] is not None: 27 | profile["age"] = updates["age"] 28 | if "preferences" in updates and updates["preferences"] is not None: 29 | profile["preferences"] = updates["preferences"] 30 | 31 | return profile 32 | 33 | # Define a correct user profile 34 | user_profile: UserProfile = { 35 | "username": "MuhammadHashim", 36 | "email": "hashim@example.com", 37 | "age": 24, 38 | "preferences": {"theme": "dark", "notifications": True} 39 | } 40 | 41 | # Define updates with an incorrect type for `age` 42 | updates: ProfileUpdates = {"age": 25, "preferences": {"theme": "light", "notifications": False}} 43 | 44 | # Apply updates (mypy will flag this as an error due to incorrect type for `age`) 45 | updated_profile = update_user_profile(user_profile, updates) 46 | print(updated_profile) 47 | -------------------------------------------------------------------------------- /02_object_oriented_programming/11_type_annotations/08_newtype/main.py: -------------------------------------------------------------------------------- 1 | from typing import NewType 2 | 3 | # Document class define kar rahe hain jo content aur review status ko handle karti hai 4 | class Document: 5 | def __init__(self, content: str): 6 | self.content = content 7 | self.reviewed = False 8 | 9 | def mark_reviewed(self): 10 | # Yeh method document ko reviewed mark kar deta hai 11 | self.reviewed = True 12 | 13 | def is_reviewed(self) -> bool: 14 | # Yeh check karta hai ke document reviewed hai ya nahi 15 | return self.reviewed 16 | 17 | # `ReadyToPublishDocument` aik naya type banate hain jo `Document` par base hai 18 | ReadyToPublishDocument = NewType('ReadyToPublishDocument', Document) 19 | 20 | # Yeh function sirf `ReadyToPublishDocument` ko accept karega 21 | def publish_document(doc: ReadyToPublishDocument): 22 | # Document ko publish karta hai 23 | print(f"Publishing document: {doc.content}") 24 | 25 | # Document ko review ke baad `ReadyToPublishDocument` mein convert karne ka function 26 | def prepare_for_publishing(doc: Document) -> ReadyToPublishDocument: 27 | # Ensure karte hain ke document reviewed hai 28 | assert doc.is_reviewed(), "Document must be reviewed before publishing" 29 | return ReadyToPublishDocument(doc) 30 | 31 | # Example workflow 32 | if __name__ == "__main__": 33 | # Ek naya draft document banate hain 34 | draft_doc = Document("Yeh aik draft content hai.") 35 | print("Initial Document:", draft_doc.content) # Output: Draft document ka content 36 | 37 | 38 | draft_doc.mark_reviewed() 39 | ready_doc = prepare_for_publishing(draft_doc) # `ReadyToPublishDocument` mein convert 40 | 41 | publish_document(ready_doc) -------------------------------------------------------------------------------- /03_data_structures/05_heaps_and_periority_queues/02_priority_queues/main.py: -------------------------------------------------------------------------------- 1 | # class for Node with data and priority 2 | class Node: 3 | def __init__(self, info, priority): 4 | self.info = info 5 | self.priority = priority 6 | 7 | # class for Priority Queue 8 | class PriorityQueue: 9 | def __init__(self): 10 | self.queue = [] 11 | 12 | def insert(self, node): 13 | # For Empty Queue 14 | if len(self.queue) == 0: 15 | self.queue.append(node) 16 | else: 17 | # traverse the queue to find the right place for new code 18 | for x in range(0, len(self.queue)): 19 | # if the property of new node is greater 20 | if node.priority >= self.queue[x].priority: 21 | # if we traverse the complete queue 22 | if x == (len(self.queue) -1): 23 | # add new node at the end 24 | self.queue.insert(x+1, node) 25 | else: 26 | continue 27 | else: 28 | self.queue.insert(x, node) 29 | return True 30 | def delete(self): 31 | # remove the first node from the queue 32 | x = self.queue.pop(0) 33 | print("Deleted data with the given priority-", x.info, x.priority) 34 | return x 35 | 36 | def show(self): 37 | for x in self.queue: 38 | print(f"{str(x.info)} - {x.priority}") 39 | 40 | 41 | 42 | p = PriorityQueue() 43 | p.insert(Node("Cat", 13)) 44 | p.insert(Node("Bat", 2)) 45 | p.insert(Node("Rat", 1)) 46 | p.insert(Node("Ant", 26)) 47 | p.insert(Node("Lion", 25)) 48 | p.show() 49 | p.delete() 50 | p.show() 51 | -------------------------------------------------------------------------------- /05_design_patterns/03_creational_design_patterns/01_factory_design_pattern/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "title": "After Dark in Central Park", 4 | "year": 1900, 5 | "director": null, 6 | "cast": null, 7 | "genre": null 8 | }, 9 | { 10 | "title": "Boarding School Girls' Pajama Parade", 11 | "year": 1900, 12 | "director": null, 13 | "cast": null, 14 | "genre": null 15 | }, 16 | { 17 | "title": "Buffalo Bill's Wild West Parad", 18 | "year": 1900, 19 | "director": null, 20 | "cast": null, 21 | "genre": null 22 | }, 23 | { 24 | "title": "Caught", 25 | "year": 1900, 26 | "director": null, 27 | "cast": null, 28 | "genre": null 29 | }, 30 | { 31 | "title": "Clowns Spinning Hats", 32 | "year": 1900, 33 | "director": null, 34 | "cast": null, 35 | "genre": null 36 | }, 37 | { 38 | "title": "Capture of Boer Battery by British", 39 | "year": 1900, 40 | "director": "James H. White", 41 | "cast": null, 42 | "genre": "Short documentary" 43 | }, 44 | { 45 | "title": "The Enchanted Drawing", 46 | "year": 1900, 47 | "director": "J. Stuart Blackton", 48 | "cast": null, 49 | "genre": null 50 | }, 51 | { 52 | "title": "Family Troubles", 53 | "year": 1900, 54 | "director": null, 55 | "cast": null, 56 | "genre": null 57 | }, 58 | { 59 | "title": "Feeding Sea Lions", 60 | "year": 1900, 61 | "director": null, 62 | "cast": "Paul Boyton", 63 | "genre": null 64 | } 65 | ] 66 | 67 | -------------------------------------------------------------------------------- /01_python_fundamentals/20_regular_expressions/01_basic_regular_expressions/problem1.5.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # Regex to match "alpha" at the start of the text 4 | regex_start_alpha = r'^\balpha\b' 5 | 6 | # Example usage 7 | text1 = "alpha is at the beginning. Not in between." 8 | text2 = "Is alpha at the beginning. Not in between." 9 | matche1 = re.findall(regex_start_alpha, text1) 10 | matche2 = re.findall(regex_start_alpha, text2) 11 | print(matche1) # Output: ['alpha'] 12 | print(matche2) # Output: No match 13 | 14 | 15 | # Regex to match "omega" at the end of the text 16 | regex_end_omega = r'\bomega\b$' 17 | # Example usage 18 | text1 = "Not in between, but omega is at the end." 19 | text2 = "Not in between, but is at the end omega" 20 | matche1 = re.findall(regex_end_omega, text1) 21 | matche2 = re.findall(regex_end_omega, text2) 22 | print(matche1) # Output: no match 23 | print(matche2) # Output: no ['omega'] 24 | 25 | 26 | # Regex to match "begin" at the start of a line 27 | regex_line_start_begin = r'^begin' 28 | # Example usage 29 | text1 = "Not in between.\nbegin is at the start of a line." 30 | text2 = "Not in between.\n begin is at the start of a line." 31 | matche1 = re.findall(regex_line_start_begin, text1, re.MULTILINE) 32 | matche2 = re.findall(regex_line_start_begin, text2, re.MULTILINE) 33 | print(matche1) # Output: ['begin'] 34 | print(matche2) # Output: no match 35 | 36 | regex_line_end_end = r'end$' 37 | 38 | # Example usage 39 | text1 = "Not in between.\nBut this line ends with end" 40 | text2 = "Not in between.\nBut this line ends end with" 41 | matche1 = re.findall(regex_line_end_end, text1, re.MULTILINE) 42 | matche2 = re.findall(regex_line_end_end, text2, re.MULTILINE) 43 | print(matche1) # Output: ['end'] 44 | print(matche2) # Output: no match -------------------------------------------------------------------------------- /02_object_oriented_programming/01_Classes/07_abstraction/03_abstraction/main.py: -------------------------------------------------------------------------------- 1 | class Browser: 2 | def navigate(self, address: str): 3 | ip = self.__find_ip_address(address) 4 | if ip is None: 5 | return "No IP address or domain found" 6 | html = self.__send_http_request(ip) 7 | return html 8 | 9 | def __find_ip_address(self, ip: str) -> str: 10 | if not ip: 11 | return None 12 | return ip 13 | 14 | def __send_http_request(self, ip: str): 15 | if self.__is_valid_ip(ip) or ip == 'localhost': 16 | return """ 17 | 18 | 19 | 20 | 21 | Document 22 | 23 | 24 |

Welcome to the website

25 | 26 | """ 27 | else: 28 | return "404 Not Found" 29 | 30 | 31 | def __is_valid_ip(self, ip: str) -> bool: 32 | parts = ip.split('.') 33 | if len(parts) == 4 and all(p.isdigit() and 0 <= int(p) <= 255 for p in parts): 34 | return True 35 | return False 36 | 37 | # Testing the code 38 | nav = Browser() 39 | print(nav.navigate('localhost')) # Should return HTML content 40 | print(nav.navigate('')) # Should return "No IP address or domain found" 41 | print(nav.navigate(None)) # Should return "No IP address or domain found" 42 | print(nav.navigate('127.0.0.1')) # Should return HTML content for the IP # Should return HTML content for a valid domain 43 | print(nav.navigate('invalid-ip')) # Should return "404 Not Found" 44 | -------------------------------------------------------------------------------- /01_python_fundamentals/21_working_with_files/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from datetime import datetime 3 | 4 | def read_logs(file_path): 5 | """Reads the existing log file and returns its content.""" 6 | try: 7 | with open(file_path, 'r') as log_file: 8 | logs = log_file.readlines() 9 | print("Existing Logs:") 10 | for log in logs: 11 | print(log.strip()) 12 | return logs 13 | except FileNotFoundError: 14 | print(f"Error: The file '{file_path}' does not exist.") 15 | return [] 16 | 17 | def append_log(file_path, log_message): 18 | """Appends a new log entry to the log file.""" 19 | with open(file_path, 'a') as log_file: 20 | timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") 21 | log_file.write(f"[{timestamp}] {log_message}\n") 22 | print(f"Log entry added: [{timestamp}] {log_message}") 23 | 24 | def write_backup(file_path, backup_path, logs): 25 | """Writes all the logs into a backup file.""" 26 | with open(backup_path, 'w') as backup_file: 27 | backup_file.writelines(logs) 28 | print(f"Backup file '{backup_path}' created successfully.") 29 | 30 | def main(): 31 | log_file_path = 'logs.txt' 32 | backup_file_path = 'logs_backup.txt' 33 | 34 | # Step 1: Read existing logs 35 | logs = read_logs(log_file_path) 36 | 37 | # Step 2: Add new log entries 38 | append_log(log_file_path, "User logged in") 39 | append_log(log_file_path, "User updated settings") 40 | 41 | # Step 3: Read logs again after appending new entries 42 | logs = read_logs(log_file_path) 43 | 44 | # Step 4: Write logs to a backup file 45 | write_backup(log_file_path, backup_file_path, logs) 46 | 47 | if __name__ == "__main__": 48 | main() 49 | --------------------------------------------------------------------------------