├── README.md ├── Session 1 - Intro to Python and Shell | Bash Scripting └── Learn Python and Shell-Bash Scripting - Session 1.pdf ├── Session 2 - Intro to Python and Shell-Bash Scripting ├── Learn Python and Shell-Bash Scripting - Session 2.pdf ├── set_bash_path_ubuntu_rhel_mac.txt ├── set_python_path_using_ansible.yml └── set_python_path_using_bash.sh ├── Session 3 - Setting up IDEs, Interpreters, Compilers for Python and Shell-Bash Scripting ├── Learn Python and Shell-Bash Scripting - Session 3.pdf ├── print_msg.py └── print_msg.sh ├── Session 4 - Let's get started with coding ├── Learn Python and Shell-Bash Scripting - Session 4.pdf ├── print_msg.py ├── print_msg.sh ├── variables.py └── variables.sh └── Session 5 - Datatypes in Python and Shell-Bash Scripting ├── Learn Python and Shell-Bash Scripting - Session 5.pdf ├── Session 5.1 - Python List ├── Python - List.pdf ├── list_append_method.py ├── list_clear_method.py ├── list_copy_method.py ├── list_count_method.py ├── list_extend_method.py ├── list_index_method.py ├── list_insert_method.py ├── list_len_method.py ├── list_pop_method.py ├── list_remove_method.py ├── list_reverse_method.py ├── list_sort_method.py └── readme.md ├── Session 5.2 - Python Dictionary ├── Python - Dictionary.pdf ├── dictionary_clear_method.py ├── dictionary_copy_method.py ├── dictionary_fromkeys_method.py ├── dictionary_get_method.py ├── dictionary_items_method.py ├── dictionary_keys_method.py ├── dictionary_pop_method.py ├── dictionary_popitem_method.py ├── dictionary_setdefault_method.py ├── dictionary_update_method.py ├── dictionary_values_method.py └── readme.md ├── Session 5.3 - Python Tuple ├── Python - Tuple.pdf ├── readme.md ├── tuple_count_method.py ├── tuple_index_method.py └── tuple_simple_code.py ├── Session 5.4 - Python Set ├── set_add_method.py ├── set_clear_method.py ├── set_difference_method.py ├── set_difference_update_method.py ├── set_discard_method.py ├── set_frozenset_method_example1.py ├── set_frozenset_method_example2.py ├── set_intersection_method.py ├── set_intersection_update.py ├── set_isdisjoint_method.py ├── set_issubset_method.py ├── set_issuperset_method.py ├── set_pop_method_example1.py ├── set_pop_method_example2.py ├── set_remove_method.py ├── set_simple_code.py ├── set_symmetric_difference_method.py ├── set_symmetric_difference_update_method.py ├── set_union_method.py └── set_update_method.py ├── bash_datatypes.sh └── python_datatypes.py /README.md: -------------------------------------------------------------------------------- 1 | # Learn Python and Bash Scripting 2 | 3 | - In this series, we are going to learn Python and Shell | Bash Scripting from basics. 4 | - From Theory -> Practicals 👨‍💻 5 | - We'll also create projects using Python and Bash Scripting. 6 | - We'll also create automations using Python and Bash Scripting. 7 | -------------------------------------------------------------------------------- /Session 1 - Intro to Python and Shell | Bash Scripting/Learn Python and Shell-Bash Scripting - Session 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 1 - Intro to Python and Shell | Bash Scripting/Learn Python and Shell-Bash Scripting - Session 1.pdf -------------------------------------------------------------------------------- /Session 2 - Intro to Python and Shell-Bash Scripting/Learn Python and Shell-Bash Scripting - Session 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 2 - Intro to Python and Shell-Bash Scripting/Learn Python and Shell-Bash Scripting - Session 2.pdf -------------------------------------------------------------------------------- /Session 2 - Intro to Python and Shell-Bash Scripting/set_bash_path_ubuntu_rhel_mac.txt: -------------------------------------------------------------------------------- 1 | - In Ubuntu, the default path for the Bash interpreter (/bin/bash) is already set by the system. 2 | - However, if you want to explicitly set the path for /bin/bash in your user environment, you can modify the ~/.bashrc file. 3 | 4 | - In RHEL (Red Hat Enterprise Linux) or CentOS, the path for the Bash interpreter (/bin/bash) is already set by default. 5 | - However, if you want to explicitly set the path for /bin/bash in your user environment, you can modify the ~/.bash_profile or ~/.bashrc file. 6 | 7 | - On macOS, the default path for the Bash interpreter (/bin/bash) is already set by the system. 8 | - However, if you want to explicitly set the path for /bin/bash in your user environment, you can modify the ~/.bash_profile or ~/.bashrc file. 9 | 10 | - Below steps are same for Ubuntu/Debian/RHEL/CentOS/Fedora/MacOS: 11 | 12 | Step 1 : Open a terminal. 13 | Step 2 : Open the ~/.bashrc file using a text editor like nano or vim: 14 | 15 | nano ~/.bashrc 16 | 17 | Step 3 : Look for a line that starts with export PATH=. 18 | Step 4 : Add /bin to the beginning of the PATH variable, separated by a colon (:). It should look like this: 19 | 20 | export PATH="/bin:$PATH" 21 | 22 | Step 5 : Save the file (Ctrl + O in nano) and exit the text editor (Ctrl + X in nano). 23 | 24 | - After making these changes, the /bin/bash path will be added to the beginning of the PATH environment variable in your user's .bashrc file. 25 | - The next time you open a terminal or start a new shell session, the modified PATH will be used, and the /bin/bash path will be available for execution. 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Session 2 - Intro to Python and Shell-Bash Scripting/set_python_path_using_ansible.yml: -------------------------------------------------------------------------------- 1 | # Replace /path/to/python/bin path with actual Python path on your system 2 | - name: Set Python path 3 | hosts: your_hosts 4 | become: true 5 | tasks: 6 | - name: Add Python path to .bashrc 7 | ansible.builtin.lineinfile: 8 | path: ~/.bashrc 9 | line: 'export PATH="/path/to/python/bin:$PATH"' 10 | state: present 11 | -------------------------------------------------------------------------------- /Session 2 - Intro to Python and Shell-Bash Scripting/set_python_path_using_bash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Replace /path/to/python/bin path with actual Python path on your system 4 | export PATH="/path/to/python/bin:$PATH" 5 | -------------------------------------------------------------------------------- /Session 3 - Setting up IDEs, Interpreters, Compilers for Python and Shell-Bash Scripting/Learn Python and Shell-Bash Scripting - Session 3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 3 - Setting up IDEs, Interpreters, Compilers for Python and Shell-Bash Scripting/Learn Python and Shell-Bash Scripting - Session 3.pdf -------------------------------------------------------------------------------- /Session 3 - Setting up IDEs, Interpreters, Compilers for Python and Shell-Bash Scripting/print_msg.py: -------------------------------------------------------------------------------- 1 | print("Hello World") 2 | -------------------------------------------------------------------------------- /Session 3 - Setting up IDEs, Interpreters, Compilers for Python and Shell-Bash Scripting/print_msg.sh: -------------------------------------------------------------------------------- 1 | echo "Hello World" 2 | 3 | printf "Hello World" 4 | -------------------------------------------------------------------------------- /Session 4 - Let's get started with coding/Learn Python and Shell-Bash Scripting - Session 4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 4 - Let's get started with coding/Learn Python and Shell-Bash Scripting - Session 4.pdf -------------------------------------------------------------------------------- /Session 4 - Let's get started with coding/print_msg.py: -------------------------------------------------------------------------------- 1 | print("Hello there,“) 2 | 3 | print("How are you\t?") 4 | 5 | print("\nI'm good :)") 6 | -------------------------------------------------------------------------------- /Session 4 - Let's get started with coding/print_msg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | printf "Hello there,“ 4 | 5 | printf "\nHow are you\t?“ 6 | 7 | printf "\n\nI'm good :)" 8 | -------------------------------------------------------------------------------- /Session 4 - Let's get started with coding/variables.py: -------------------------------------------------------------------------------- 1 | Value="Python & Bash Scripting Score" 2 | print("Value: {}\n".format(Value)) 3 | 4 | Value=95 5 | print("Value: {}\n".format(Value)) 6 | 7 | Value=95.0 8 | print("Value: {}".format(Value)) 9 | -------------------------------------------------------------------------------- /Session 4 - Let's get started with coding/variables.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Value="Python & Bash Scripting Score“ 4 | printf "Value: ${Value}\n\n“ 5 | Value=95 6 | printf "Value: ${Value}\n\n“ 7 | Value=95.0 8 | printf "Value: ${Value}\n\n" 9 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Learn Python and Shell-Bash Scripting - Session 5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 5 - Datatypes in Python and Shell-Bash Scripting/Learn Python and Shell-Bash Scripting - Session 5.pdf -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/Python - List.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/Python - List.pdf -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_append_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - append() 3 | 4 | Description: The append() method adds an item to the end of the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha"] 9 | 10 | # Printing Punjabi Menu List 11 | print("Punjabi Menu: {}".format(PUNJABI)) 12 | 13 | # Adding one more menu item in PUNJABI list 14 | PUNJABI.append("Plain Roti") 15 | 16 | # Finally, printing Punjabi Menu List again 17 | print("Punjabi Menu: {}".format(PUNJABI)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha'] 23 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 24 | """ 25 | 26 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_clear_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - clear() 3 | 4 | Description: The clear() method removes all items from the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ['Butter Naan', 'Butter Roti', 'Dal Makhni', 'Paneer Makhni', 'Paneer Tikka Masala', 'Plain Roti', 'Pudhina Paratha', 'Rajma'] 9 | 10 | # Printing Punjabi Menu List 11 | print("PUNJABI Menu: {}".format(PUNJABI)) 12 | 13 | # Clearing PUNJABI menu list. 14 | PUNJABI.clear() 15 | 16 | # Finally, printing Punjabi Menu List again 17 | print("Punjabi Menu: {}".format(PUNJABI)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | PUNJABI Menu: ['Butter Naan', 'Butter Roti', 'Dal Makhni', 'Paneer Makhni', 'Paneer Tikka Masala', 'Plain Roti', 'Pudhina Paratha', 'Rajma'] 23 | Punjabi Menu: [] 24 | """ 25 | 26 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_copy_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - copy() 3 | 4 | Description: The copy() method returns a shallow copy of the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | TEMP_MENU = ['Butter Naan', 'Butter Roti', 'Dal Makhni', 'Paneer Makhni', 'Paneer Tikka Masala', 'Plain Roti', 'Pudhina Paratha', 'Rajma'] 9 | 10 | # Printing Punjabi Menu List 11 | print("TEMP Menu: {}".format(TEMP_MENU)) 12 | 13 | # Copying TEMP_MENU list to PUNJABI. 14 | PUNJABI = TEMP_MENU.copy() 15 | 16 | # Finally, printing Punjabi Menu List 17 | print("Punjabi Menu: {}".format(PUNJABI)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | TEMP Menu: ['Butter Naan', 'Butter Roti', 'Dal Makhni', 'Paneer Makhni', 'Paneer Tikka Masala', 'Plain Roti', 'Pudhina Paratha', 'Rajma'] 23 | Punjabi Menu: ['Butter Naan', 'Butter Roti', 'Dal Makhni', 'Paneer Makhni', 'Paneer Tikka Masala', 'Plain Roti', 'Pudhina Paratha', 'Rajma'] 24 | """ 25 | 26 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_count_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - count() 3 | 4 | Description: The count() method returns the number of times the specified element appears in the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Plain Roti", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha", "Plain Roti"] 9 | 10 | # Printing Punjabi Menu List 11 | print("Punjabi Menu: {}".format(PUNJABI)) 12 | 13 | # Counting number of times ‘Plain Roti’ item appeared in Punjabi Menu 14 | count_of_item = PUNJABI.count("Plain Roti") 15 | 16 | # Finally, printing number of times ‘Plain Roti’ item appeared in Punjabi Menu 17 | print("Number of times ‘Plain Roti’ item appeared in Punjabi Menu: {}".format(count_of_item)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Plain Roti', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 23 | Number of times ‘Plain Roti’ item appeared in Punjabi Menu: 2 24 | """ 25 | 26 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_extend_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - extend() 3 | 4 | Description: The extend() method adds all the elements of an iterable (list, tuple, string etc.) to the end of the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan"] 9 | 10 | # Printing Punjabi Menu List 11 | print("Punjabi Menu: {}".format(PUNJABI)) 12 | 13 | # Speciality in our Punjabi Menu List 14 | SPECIALITY = ["Pudhina Paratha", "Plain Roti"] 15 | 16 | # Adding Speciality items in PUNJABI menu list 17 | PUNJABI.extend(SPECIALITY) 18 | 19 | # Finally, printing Punjabi Menu List again 20 | print("Punjabi Menu: {}".format(PUNJABI)) 21 | 22 | """ 23 | Output - 24 | --------------------------------------------------------------- 25 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan'] 26 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 27 | """ 28 | 29 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_index_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - index() 3 | 4 | Description: The index() method returns the index of the specified element in the list. 5 | 6 | Note - List index start with 0. 7 | """ 8 | 9 | # Creating a list for Punjabi Menu 10 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha", "Plain Roti"] 11 | 12 | # Printing Punjabi Menu List 13 | print("Punjabi Menu: {}".format(PUNJABI)) 14 | 15 | # Getting index of 'Plain Roti' item in PUNJABI list. 16 | index_of_item = PUNJABI.index("Plain Roti") 17 | 18 | # Finally, printing index of 'Plain Roti' item in Punjabi Menu 19 | print("Index of 'Plain Roti' item in Punjabi Menu: {}".format(index_of_item)) 20 | 21 | """ 22 | Output - 23 | --------------------------------------------------------------- 24 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 25 | Index of 'Plain Roti' item in Punjabi Menu: 7 26 | """ 27 | 28 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_insert_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - insert() 3 | 4 | Description: The insert() method inserts an element to the list at the specified index. 5 | 6 | Note - List index start with 0. 7 | """ 8 | 9 | # Creating a list for Punjabi Menu 10 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha"] 11 | 12 | # Printing Punjabi Menu List 13 | print("Punjabi Menu: {}".format(PUNJABI)) 14 | 15 | # Adding one more menu item 'Plain Roti' in PUNJABI list at index 4 but in Python index starts with 0, so it will be 3. 16 | PUNJABI.insert(3, "Plain Roti") 17 | 18 | # Finally, printing Punjabi Menu List again 19 | print("Punjabi Menu: {}".format(PUNJABI)) 20 | 21 | """ 22 | Output - 23 | --------------------------------------------------------------- 24 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha'] 25 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Plain Roti', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha'] 26 | """ 27 | 28 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_len_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - len() 3 | 4 | Description: The len() method returns the number of items present in the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha"] 9 | 10 | # Counting number of items present in PUNJABI list 11 | count_of_items = len(PUNJABI) 12 | 13 | # Finally, printing Count of Items in Punjabi Menu List 14 | print("Count of Items in Punjabi Menu: {}".format(count_of_items)) 15 | 16 | """ 17 | Output - 18 | --------------------------------------------------------------- 19 | Count of Items in Punjabi Menu: 7 20 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_pop_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - pop() 3 | 4 | Description: The pop() method removes the item at the specified index. 5 | 6 | Note - List index start with 0. 7 | """ 8 | 9 | # Creating a list for Punjabi Menu 10 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Plain Roti", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha"] 11 | 12 | # Printing Punjabi Menu List 13 | print("Punjabi Menu: {}".format(PUNJABI)) 14 | 15 | # Removing 'Plain Roti' item from PUNJABI list which at index 4 but in Python index starts with 0, so it will be 3. 16 | PUNJABI.pop(3) 17 | 18 | # Finally, printing Punjabi Menu List again 19 | print("Punjabi Menu: {}".format(PUNJABI)) 20 | 21 | """ 22 | Output - 23 | --------------------------------------------------------------- 24 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Plain Roti', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha'] 25 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha'] 26 | """ 27 | 28 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_remove_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - remove() 3 | 4 | Description: The remove() method removes the first matching element. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha", "Plain Roti"] 9 | 10 | # Printing Punjabi Menu List 11 | print("Punjabi Menu: {}".format(PUNJABI)) 12 | 13 | # Removing 'Plain Roti' menu item from PUNJABI list 14 | PUNJABI.remove("Plain Roti") 15 | 16 | # Finally, printing Punjabi Menu List again 17 | print("Punjabi Menu: {}".format(PUNJABI)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 23 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha'] 24 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_reverse_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - reverse() 3 | 4 | Description: The reverse() method reverses the elements of the list. 5 | """ 6 | 7 | # Creating a list for Punjabi Menu 8 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha", "Plain Roti"] 9 | 10 | # Printing Punjabi Menu List 11 | print("Punjabi Menu: {}".format(PUNJABI)) 12 | 13 | # Reversing the PUNJABI menu list. 14 | PUNJABI.reverse() 15 | 16 | # Finally, printing Punjabi Menu List again 17 | print("Punjabi Menu: {}".format(PUNJABI)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 23 | Punjabi Menu: ['Plain Roti', 'Pudhina Paratha', 'Butter Naan', 'Butter Roti', 'Paneer Makhni', 'Paneer Tikka Masala', 'Rajma', 'Dal Makhni'] 24 | """ 25 | 26 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/list_sort_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - sort() 3 | 4 | Description: The sort() method sorts the items of a list in ascending or descending order. 5 | 6 | Note: Default sort is Ascending sort. 7 | """ 8 | 9 | # Creating a list for Punjabi Menu 10 | PUNJABI = ["Dal Makhni", "Rajma", "Paneer Tikka Masala", "Paneer Makhni", "Butter Roti", "Butter Naan", "Pudhina Paratha", "Plain Roti"] 11 | 12 | # Printing Punjabi Menu List 13 | print("Punjabi Menu: {}".format(PUNJABI)) 14 | 15 | # You can use any of below syntax to sort in ascending order. 16 | # For Ascending order use -> PUNJABI.sort() or PUNJABI.sort(reverse=False) 17 | PUNJABI.sort(reverse=False) 18 | 19 | # Finally, printing Punjabi Menu List again 20 | print("Punjabi Menu in Ascending Order: {}".format(PUNJABI)) 21 | 22 | # For Descending order use -> PUNJABI.sort(reverse=True) 23 | PUNJABI.sort(reverse=True) 24 | 25 | # Finally, printing Punjabi Menu List again 26 | print("Punjabi Menu in Descending Order: {}".format(PUNJABI)) 27 | 28 | """ 29 | Output - 30 | --------------------------------------------------------------- 31 | Punjabi Menu: ['Dal Makhni', 'Rajma', 'Paneer Tikka Masala', 'Paneer Makhni', 'Butter Roti', 'Butter Naan', 'Pudhina Paratha', 'Plain Roti'] 32 | Punjabi Menu in Ascending Order: ['Butter Naan', 'Butter Roti', 'Dal Makhni', 'Paneer Makhni', 'Paneer Tikka Masala', 'Plain Roti', 'Pudhina Paratha', 'Rajma'] 33 | Punjabi Menu in Descending Order: ['Rajma', 'Pudhina Paratha', 'Plain Roti', 'Paneer Tikka Masala', 'Paneer Makhni', 'Dal Makhni', 'Butter Roti', 'Butter Naan'] 34 | """ 35 | 36 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.1 - Python List/readme.md: -------------------------------------------------------------------------------- 1 | # Learn about Python List and methods for Python List 2 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/Python - Dictionary.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/Python - Dictionary.pdf -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_clear_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - clear() 3 | 4 | Description: Removes all items from the dictionary. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Printing Electronics Shop Inventory 11 | print('Electronics Shop Inventory:', inventory) 12 | 13 | # Clear the Electronics Shop Inventory 14 | inventory.clear() 15 | 16 | # Printing Electronics Inventory after clearing it 17 | print('Electronics Shop Inventory after clearing it:', inventory) 18 | 19 | 20 | """ 21 | Output - 22 | --------------------------------------------------------------- 23 | Electronics Shop Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 24 | Electronics Shop Inventory after clearing it: {} 25 | """ 26 | 27 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_copy_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - copy() 3 | 4 | Description: Returns a copy (shallow copy) of the dictionary. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Copying the original inventory 11 | copied_inventory = inventory.copy() 12 | 13 | # Printing Original Electronics Inventory 14 | print('Original Inventory:', inventory) 15 | 16 | # Printing Copied Electronics Inventory 17 | print('Copied Inventory:', copied_inventory) 18 | 19 | 20 | """ 21 | Output - 22 | --------------------------------------------------------------- 23 | Original Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 24 | Copied Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 25 | """ 26 | 27 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_fromkeys_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - fromkeys() 3 | 4 | Description: Creates a dictionary from the given sequence of keys and values. 5 | """ 6 | 7 | # keys for the dictionary 8 | item_brand = {'Samsung', 'iPhone', 'Nothing'} 9 | 10 | # value for the dictionary 11 | item_category = 'Smartphone' 12 | 13 | # Now create an inventory dictionary from the given sequence of keys - item_brand and values - item_category 14 | inventory = dict.fromkeys(item_brand, item_category) 15 | 16 | # Printing Electronics Inventory 17 | print('Electronics Shop Inventory:', inventory) 18 | 19 | 20 | """ 21 | Output - 22 | --------------------------------------------------------------- 23 | Electronics Shop Inventory: {'iPhone': 'Smartphone', 'Nothing': 'Smartphone', 'Samsung': 'Smartphone'} 24 | """ 25 | 26 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_get_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - get() 3 | 4 | Description: Returns the value for the specified key if the key is in the dictionary. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Printing Smartphone Item Stock 11 | print("Smartphones in Stock: {}".format(inventory.get('Smartphone'))) 12 | 13 | """ 14 | Output - 15 | --------------------------------------------------------------- 16 | Smartphones in Stock: 15 17 | """ 18 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_items_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - items() 3 | 4 | Description: Returns a view object that displays a list of dictionary's (key, value) tuple pairs. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Printing Electronics Shop Inventory Dictionary 11 | print("Inventory: {}".format(inventory.items())) 12 | 13 | """ 14 | Output - 15 | --------------------------------------------------------------- 16 | Inventory: dict_items([('Laptop', 10), ('Smartphone', 15), ('Tablet', 5), ('Headphones', 20)]) 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_keys_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - keys() 3 | 4 | Description: Extracts the keys of the dictionary and returns the list of keys as a view object. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Extracts the Keys of the Dictionary 11 | dictionaryKeys = inventory.keys() 12 | 13 | # Printing Electronics Shop Inventory Dictionary Keys 14 | print("Inventory Items: {}".format(dictionaryKeys)) 15 | 16 | """ 17 | Output - 18 | --------------------------------------------------------------- 19 | Inventory Items: dict_keys(['Laptop', 'Smartphone', 'Tablet', 'Headphones']) 20 | """ 21 | 22 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_pop_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - pop() 3 | 4 | Description: Removes and returns an element from a dictionary having the given key. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20, 'Air Conditioner' : 8} 9 | 10 | # Printing Electronics Shop Inventory 11 | print('Electronics Shop Inventory:', inventory) 12 | 13 | # Removing 'Air Conditioner' item from inventory 14 | remove_element = inventory.pop('Air Conditioner') 15 | 16 | # Printing Electronics Shop Inventory after removing the item 'Air Conditioner' 17 | print('Electronics Shop Inventory after removing the item:', inventory) 18 | 19 | 20 | """ 21 | Output - 22 | --------------------------------------------------------------- 23 | Electronics Shop Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20, 'Air Conditioner': 8} 24 | Electronics Shop Inventory after removing the element: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 25 | """ 26 | 27 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_popitem_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - popitem() 3 | 4 | Description: Removes and returns the last element (key, value) pair inserted into the dictionary. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 9 | 10 | # Printing Electronics Shop Inventory 11 | print('Electronics Shop Inventory:', inventory) 12 | 13 | # Removing last item from inventory 14 | remove_element = inventory.popitem() 15 | 16 | # Printing what item got removed from inventory 17 | print('Removed Element:', remove_element) 18 | 19 | # Printing Electronics Shop Inventory after removing the last itm of inventory 20 | print('Electronics Shop Inventory after removing the last item:', inventory) 21 | 22 | 23 | """ 24 | Output - 25 | --------------------------------------------------------------- 26 | Electronics Shop Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 27 | Removed Element: ('Headphones', 20) 28 | Electronics Shop Inventory after removing the last element: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5} 29 | """ 30 | 31 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_setdefault_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - setdefault() 3 | 4 | Description: Returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the 5 | dictionary. 6 | """ 7 | 8 | # Creating a dictionary for Electronics Shop Inventory 9 | inventory = {'Nothing': 'Smartphone', 'Samsung': 'Smartphone', 'iPhone': 'Smartphone'} 10 | 11 | # Printing Electronics Inventory 12 | print('Electronics Shop Inventory:', inventory) 13 | 14 | # Nokia was not present in above dictionary still will give its default value set in below 15 | item_category = inventory.setdefault('Nokia', 'Smartphone') 16 | 17 | print('Item Category =', item_category) 18 | 19 | # Now here you can also see that Nokia key with value has been added 20 | print('Electronics Shop Inventory after using setdefault method:', inventory) 21 | 22 | 23 | """ 24 | Output - 25 | --------------------------------------------------------------- 26 | Electronics Shop Inventory: {'Nothing': 'Smartphone', 'Samsung': 'Smartphone', 'iPhone': 'Smartphone'} 27 | Item Category = Smartphone 28 | Electronics Shop Inventory after using setdefault method: {'Nothing': 'Smartphone', 'Samsung': 'Smartphone', 'iPhone': 'Smartphone', 'Nokia': 'Smartphone'} 29 | """ 30 | 31 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_update_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - update() 3 | 4 | Description: Updates the dictionary with the elements from another dictionary object or from an iterable of key/value pairs. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Printing Electronics Shop Inventory 11 | print('Electronics Shop Inventory:', inventory) 12 | 13 | # Creating new_items dictionary with new electronics item 14 | new_items = {'Air Conditioner': 8} 15 | 16 | # Updating the Electronics Shop Inventory with new_items dictionary 17 | inventory.update(new_items) 18 | 19 | # Printing Copied Electronics Inventory 20 | print('Electronics Shop Inventory:', inventory) 21 | 22 | 23 | """ 24 | Output - 25 | --------------------------------------------------------------- 26 | Electronics Shop Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20} 27 | Electronics Shop Inventory: {'Laptop': 10, 'Smartphone': 15, 'Tablet': 5, 'Headphones': 20, 'Air Conditioner': 8} 28 | """ 29 | 30 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/dictionary_values_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - values() 3 | 4 | Description: Returns a view object that displays a list of all the values in the dictionary. 5 | """ 6 | 7 | # Creating a dictionary for Electronics Shop Inventory 8 | inventory = {"Laptop": 10, "Smartphone": 15, "Tablet": 5, "Headphones": 20} 9 | 10 | # Extracts the Values of the Dictionary 11 | dictionaryValues = inventory.values() 12 | 13 | # Printing Electronics Shop Inventory Dictionary Keys 14 | print("Inventory Items Stock: {}".format(dictionaryValues)) 15 | 16 | """ 17 | Output - 18 | --------------------------------------------------------------- 19 | Inventory Items Stock: dict_values([10, 15, 5, 20]) 20 | """ 21 | 22 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.2 - Python Dictionary/readme.md: -------------------------------------------------------------------------------- 1 | # Learn about Python Dictionary and methods for Python Dictionary 2 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.3 - Python Tuple/Python - Tuple.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/themr255/Learn-Python-Bash-Scripting/52f2e6fbe4ee6d1267d4c6d536e797c803f01bcb/Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.3 - Python Tuple/Python - Tuple.pdf -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.3 - Python Tuple/readme.md: -------------------------------------------------------------------------------- 1 | # Learn about Python Tuple and methods for Python Tuple 2 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.3 - Python Tuple/tuple_count_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - count() 3 | 4 | Description: Returns the number of times the specified element appears in the tuple. 5 | """ 6 | 7 | # Creating cartoon_characters tuple containing cartoon characters 8 | cartoon_characters = ('Turtle', 'Rabbit', 'Unicorn', 'Rabbit') 9 | print("Cartoon Characters Tuple:", cartoon_characters) 10 | 11 | # counts the number of times Rabbit appeared in the tuple 12 | count_of_rabbit = cartoon_characters.count('Rabbit') 13 | 14 | # Printing how many times 'Rabbit' appeared in cartoon_characters tuple 15 | print("Count of Rabbit in Cartoon Characters Tuple:", count_of_rabbit) 16 | 17 | """ 18 | Output - 19 | --------------------------------------------------------------- 20 | Cartoon Characters Tuple: ('Turtle', 'Rabbit', 'Unicorn', 'Rabbit') 21 | Count of Rabbit in Cartoon Characters Tuple: 2 22 | """ 23 | 24 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.3 - Python Tuple/tuple_index_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - index() 3 | 4 | Description: Returns the index of the specified element in the tuple. 5 | """ 6 | 7 | # Creating cartoon_characters tuple containing cartoon characters 8 | cartoon_characters = ('Turtle', 'Rabbit', 'Unicorn') 9 | print("Cartoon Characters Tuple:", cartoon_characters) 10 | 11 | # Getting index of 'Unicorn' in vowels 12 | index_of_unicorn = cartoon_characters.index('Unicorn') 13 | 14 | print("Index of Unicorn in Cartoon Characters Tuple:", index_of_unicorn) 15 | 16 | """ 17 | Output - 18 | --------------------------------------------------------------- 19 | Cartoon Characters Tuple: ('Turtle', 'Rabbit', 'Unicorn') 20 | Index of Unicorn in Cartoon Characters Tuple: 2 21 | """ 22 | 23 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.3 - Python Tuple/tuple_simple_code.py: -------------------------------------------------------------------------------- 1 | """ 2 | Description: Simple code to declare tuple and printing it. 3 | """ 4 | 5 | # Creating cartoon_characters tuple containing cartoon characters 6 | cartoon_characters = ('Turtle', 'Rabbit', 'Unicorn') 7 | 8 | # Print the tuple containing cartoon characters 9 | print("Cartoon Characters Tuple:", cartoon_characters) 10 | 11 | """ 12 | Output - 13 | --------------------------------------------------------------- 14 | Cartoon Characters Tuple: ('Turtle', 'Rabbit', 'Unicorn') 15 | """ 16 | 17 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_add_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - add() 3 | 4 | Description: Adds a given element to a set. If the element is already present, it doesn't add any element. 5 | """ 6 | 7 | # Create a Set of travel destinations in Sri Lanka 8 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 9 | 10 | # Print the original set of travel destinations 11 | print("Original travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 12 | 13 | # Add a new travel destination using the 'add' method 14 | travel_destinations.add("Jaffna") 15 | 16 | # Print the updated set of travel destinations 17 | print("\nUpdated travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | Original travel destinations in Sri Lanka: 23 | {'Galle', 'Ella', 'Polonnaruwa', 'Nuwara Eliya', 'Mirissa', 'Sigiriya', 'Colombo', 'Kandy'} 24 | 25 | Updated travel destinations in Sri Lanka: 26 | {'Galle', 'Ella', 'Polonnaruwa', 'Nuwara Eliya', 'Mirissa', 'Sigiriya', 'Colombo', 'Kandy', 'Jaffna'} 27 | 28 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_clear_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - clear() 3 | 4 | Description: Removes all items from the set. 5 | """ 6 | 7 | # Create a Set of travel destinations in Sri Lanka 8 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 9 | 10 | # Print the original set of travel destinations 11 | print("Original travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 12 | 13 | # Clear the set using the 'clear' method 14 | travel_destinations.clear() 15 | 16 | # Print the updated set of travel destinations 17 | print("\nUpdated travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 18 | 19 | """ 20 | Output - 21 | --------------------------------------------------------------- 22 | Original travel destinations in Sri Lanka: 23 | {'Galle', 'Ella', 'Colombo', 'Polonnaruwa', 'Sigiriya', 'Kandy', 'Nuwara Eliya', 'Mirissa'} 24 | 25 | Updated travel destinations in Sri Lanka: 26 | set() 27 | 28 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_difference_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - difference() 3 | 4 | Description: Returns a set that contains the difference between two sets. 5 | """ 6 | 7 | # Define playlists as sets of songs 8 | ed_sheeran_playlist = {"Thinking Out Loud", "Perfect", "Photograph", "Shape of You"} 9 | mix_english_songs_playlist = {"Photograph", "Shape of You", "Too Good At Goodbyes", "Girls Like You", "Faded", "Happier"} 10 | 11 | # Print the set of Ed Sheeran Songs Playlist 12 | print("Ed Sheeran Playlist:", ed_sheeran_playlist) 13 | 14 | # Print the set of Mix English Songs Playlist 15 | print("Mix English Playlist:", mix_english_songs_playlist) 16 | 17 | # Find the difference between ed_sheeran_playlist and mix_english_songs_playlist 18 | ed_sheeran_song_not_in_mix_english_songs = ed_sheeran_playlist.difference(mix_english_songs_playlist) 19 | 20 | # Print the which Ed Sheeran Playlist not present in Mix English Playlist 21 | print("\nEd Sheeran Songs not in Mix English Playlist:", ed_sheeran_song_not_in_mix_english_songs) 22 | 23 | 24 | """ 25 | Output - 26 | --------------------------------------------------------------- 27 | Ed Sheeran Playlist: {'Shape of You', 'Thinking Out Loud', 'Photograph', 'Perfect'} 28 | Mix English Playlist: {'Too Good At Goodbyes', 'Shape of You', 'Photograph', 'Girls Like You', 'Happier', 'Faded'} 29 | 30 | Ed Sheeran Songs not in Mix English Playlist: {'Thinking Out Loud', 'Perfect'} 31 | 32 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_difference_update_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - difference_update() 3 | 4 | Description: Computes the difference between two sets (A - B) and updates set A with the resulting set. 5 | """ 6 | 7 | # Define playlists as sets of songs 8 | mix_english_songs_playlist = {"Photograph", "Shape of You", "Too Good At Goodbyes", "Girls Like You", "Faded", "Happier"} 9 | ed_sheeran_playlist = {"Thinking Out Loud", "Perfect", "Photograph", "Shape of You"} 10 | 11 | # Print the set of Mix English Songs Playlist 12 | print("Mix English Playlist:", mix_english_songs_playlist) 13 | 14 | # Print the set of Ed Sheeran Songs Playlist 15 | print("Ed Sheeran Playlist:", ed_sheeran_playlist) 16 | 17 | # Here we can see few ed_sheeran_playlist songs present in mix_english_songs_playlist 18 | # So remove all Ed Sheeran songs from mix_english_songs_playlist 19 | mix_english_songs_playlist.difference_update(ed_sheeran_playlist) 20 | 21 | # Print the which Ed Sheeran Playlist not present in Mix English Playlist 22 | print("\nMix English Playlist after removing Ed Sheeran Songs:", mix_english_songs_playlist) 23 | 24 | 25 | """ 26 | Output - 27 | --------------------------------------------------------------- 28 | Mix English Playlist: {'Photograph', 'Shape of You', 'Girls Like You', 'Happier', 'Too Good At Goodbyes', 'Faded'} 29 | Ed Sheeran Playlist: {'Perfect', 'Thinking Out Loud', 'Photograph', 'Shape of You'} 30 | 31 | Mix English Playlist after removing Ed Sheeran Songs: {'Girls Like You', 'Happier', 'Too Good At Goodbyes', 'Faded'} 32 | 33 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_discard_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - discard() 3 | 4 | Description: Used to remove a specific element from a set if it exists in the set. If the element is not present in the set, the discard method does nothing and doesn't raise any errors. 5 | """ 6 | 7 | # Create a Set of travel destinations in Sri Lanka 8 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 9 | 10 | # Use the 'copy' method to create a copy of the set 11 | copied_destinations = travel_destinations.copy() 12 | 13 | # Print the original set of travel destinations 14 | print("\nOriginal travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 15 | 16 | # Destination to discard 17 | destination_to_discard = "Sigiriya" 18 | 19 | # Use the 'discard' method to remove a travel destination (if it exists) 20 | travel_destinations.discard(destination_to_discard) 21 | 22 | # Print the updated set of travel destinations 23 | print("\nUpdated travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 24 | 25 | """ 26 | Output - 27 | --------------------------------------------------------------- 28 | Original travel destinations in Sri Lanka: 29 | {'Sigiriya', 'Colombo', 'Polonnaruwa', 'Kandy', 'Galle', 'Ella', 'Mirissa', 'Nuwara Eliya'} 30 | 31 | Updated travel destinations in Sri Lanka: 32 | {'Colombo', 'Polonnaruwa', 'Kandy', 'Galle', 'Ella', 'Mirissa', 'Nuwara Eliya'} 33 | 34 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_frozenset_method_example1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - frozenset() 3 | 4 | Description: Immutable version of a Python set object. While elements of a set can be modified at any time, 5 | elements of the frozen set remain the same after creation. 6 | Once you create a frozenset, you cannot modify it by adding or removing elements. 7 | """ 8 | 9 | # Create a Set of travel destinations in Sri Lanka 10 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 11 | 12 | # Print the original set of travel destinations 13 | print("Original travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 14 | 15 | # Convert the travel_destinations set to a frozenset 16 | frozen_destinations = frozenset(travel_destinations) 17 | 18 | # Attempt to add a new destination to the frozenset (this will raise an error) 19 | try: 20 | frozen_destinations.add("Galle") 21 | except AttributeError: 22 | print("\nCannot add to a frozenset.") 23 | 24 | # Attempt to remove a destination from the frozenset (this will also raise an error) 25 | try: 26 | frozen_destinations.remove("Mirissa") 27 | except AttributeError: 28 | print("\nCannot remove from a frozenset.") 29 | 30 | # Print the set of travel destinations 31 | print("\nTravel destinations in Sri Lanka: \n{}".format(travel_destinations)) 32 | 33 | """ 34 | Output - 35 | --------------------------------------------------------------- 36 | Original travel destinations in Sri Lanka: 37 | {'Mirissa', 'Galle', 'Ella', 'Nuwara Eliya', 'Sigiriya', 'Polonnaruwa', 'Kandy', 'Colombo'} 38 | 39 | Cannot add to a frozenset. 40 | 41 | Cannot remove from a frozenset. 42 | 43 | Travel destinations in Sri Lanka: 44 | {'Mirissa', 'Galle', 'Ella', 'Nuwara Eliya', 'Sigiriya', 'Polonnaruwa', 'Kandy', 'Colombo'} 45 | 46 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_frozenset_method_example2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - frozenset() 3 | 4 | Description: Immutable version of a Python set object. While elements of a set can be modified at any time, 5 | elements of the frozen set remain the same after creation. 6 | Once you create a frozenset, you cannot modify it by adding or removing elements. 7 | """ 8 | 9 | # Define user roles and their permissions using frozensets 10 | admin_permissions = frozenset(["create", "read", "update", "delete"]) 11 | editor_permissions = frozenset(["read", "update"]) 12 | viewer_permissions = frozenset(["read"]) 13 | 14 | # Store user roles and their permissions 15 | user_roles = { 16 | "admin": admin_permissions, 17 | "editor": editor_permissions, 18 | "viewer": viewer_permissions, 19 | } 20 | 21 | for user in user_roles: 22 | print("User Type: {}".format(user)) 23 | print("User has permission to create: {}".format(user_roles[user])) 24 | 25 | # Attempt to add a new destination to the frozenset (this will raise an error) 26 | try: 27 | viewer_permissions.add("create") 28 | except AttributeError: 29 | print("\nCannot add 'create' permission to a viewer_permissions frozenset.") 30 | 31 | """ 32 | Output - 33 | --------------------------------------------------------------- 34 | User Type: admin 35 | User has permission to create: frozenset({'delete', 'read', 'create', 'update'}) 36 | User Type: editor 37 | User has permission to create: frozenset({'read', 'update'}) 38 | User Type: viewer 39 | User has permission to create: frozenset({'read'}) 40 | 41 | Cannot add 'create' permission to a viewer_permissions frozenset. 42 | 43 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_intersection_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - intersection() 3 | 4 | Description: Returns a new set with elements that are common to all sets. 5 | """ 6 | 7 | # Define playlists as sets of songs 8 | ed_sheeran_playlist = {"Thinking Out Loud", "Perfect", "Photograph", "Shape of You"} 9 | mix_english_songs_playlist = {"Photograph", "Shape of You", "Too Good At Goodbyes", "Girls Like You", "Faded", "Happier"} 10 | 11 | # Print the set of Ed Sheeran Songs Playlist 12 | print("Ed Sheeran Playlist:", ed_sheeran_playlist) 13 | 14 | # Print the set of Mix English Songs Playlist 15 | print("Mix English Playlist:", mix_english_songs_playlist) 16 | 17 | # Find the common songs between ed_sheeran_playlist and mix_english_songs_playlist 18 | common_songs = ed_sheeran_playlist.intersection(mix_english_songs_playlist) 19 | 20 | # Print the common songs from both Ed Sheeran and Mix English Playlist 21 | print("\nCommon Songs present in Ed Sheeran and Mix English Playlist:", common_songs) 22 | 23 | 24 | """ 25 | Output - 26 | --------------------------------------------------------------- 27 | Ed Sheeran Playlist: {'Photograph', 'Perfect', 'Thinking Out Loud', 'Shape of You'} 28 | Mix English Playlist: {'Girls Like You', 'Faded', 'Photograph', 'Too Good At Goodbyes', 'Happier', 'Shape of You'} 29 | 30 | Common Songs present in Ed Sheeran and Mix English Playlist: {'Shape of You', 'Photograph'} 31 | 32 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_intersection_update.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - intersection_update() 3 | 4 | Description: Finds the intersection of different sets and updates it to the set that calls the method. 5 | """ 6 | 7 | # Define playlists as sets of songs 8 | rock_playlist = {"Bohemian Rhapsody", "Stairway to Heaven", "Hotel California"} 9 | pop_playlist = {"Shape of You", "Uptown Funk", "Bohemian Rhapsody"} 10 | 11 | # Print the set of Ed Sheeran Songs Playlist 12 | print("Ed Sheeran Playlist:", rock_playlist) 13 | 14 | # Print the set of Mix English Songs Playlist 15 | print("Mix English Playlist:", pop_playlist) 16 | 17 | # Use intersection_update to update rock_playlist with songs in common with pop_playlist 18 | rock_playlist.intersection_update(pop_playlist) 19 | 20 | # Print the updated Rock Songs Playlist 21 | print("\nRock and Pop Song:", rock_playlist) 22 | 23 | 24 | """ 25 | Output - 26 | --------------------------------------------------------------- 27 | Ed Sheeran Playlist: {'Hotel California', 'Stairway to Heaven', 'Bohemian Rhapsody'} 28 | Mix English Playlist: {'Uptown Funk', 'Shape of You', 'Bohemian Rhapsody'} 29 | 30 | Rock and Pop Song: {'Bohemian Rhapsody'} 31 | 32 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_isdisjoint_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - isdisjoint() 3 | 4 | Description: Returns True if two sets don't have any common items between them, i.e. they are disjoint. Else the 5 | returns False. """ 6 | 7 | # Define sets representing different finish options for Asian Paints color products 8 | smooth_finish_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White"} 9 | ultra_sheen_finish_colors = {"Satin Blue", "Glossy Black", "Metallic Silver"} 10 | 11 | # Print the set of smooth_finish_colors 12 | print("Smooth Finish Colors:", smooth_finish_colors) 13 | 14 | # Print the set of ultra_sheen_finish_colors 15 | print("Ultra Sheen Finish Colors:", ultra_sheen_finish_colors) 16 | 17 | # Check if two sets - smooth_finish_colors and ultra_sheen_finish_colors have no common elements 18 | are_disjoint = smooth_finish_colors.isdisjoint(ultra_sheen_finish_colors) 19 | 20 | # Here smooth_finish_colors and ultra_sheen_finish_colors sets have one common color - Satin Blue 21 | # So these sets are not Disjoint 22 | 23 | # Print the all the colors present in both color type 24 | print("\nAre Sets Disjoint:", are_disjoint) 25 | 26 | 27 | """ 28 | Output - 29 | --------------------------------------------------------------- 30 | Smooth Finish Colors: {'Antique White', 'Classic Ivory', 'Satin Blue', 'Silk White'} 31 | Ultra Sheen Finish Colors: {'Satin Blue', 'Metallic Silver', 'Glossy Black'} 32 | 33 | Are Sets Disjoint: False 34 | 35 | """ 36 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_issubset_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - issubset() 3 | 4 | Description: Returns True if set A is the subset of B, i.e. if all the elements of set A are present in set B . 5 | Else, it returns False 6 | """ 7 | 8 | # Define sets representing different finish options for Asian Paints color products 9 | smooth_finish_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White"} 10 | ultra_sheen_finish_colors = {"Satin Blue", "Glossy Black", "Metallic Silver"} 11 | 12 | mix_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White", "Glossy Black", "Metallic Silver"} 13 | 14 | # Print the set of smooth_finish_colors 15 | print("Smooth Finish Colors:", smooth_finish_colors) 16 | 17 | # Print the set of ultra_sheen_finish_colors 18 | print("Ultra Sheen Finish Colors:", ultra_sheen_finish_colors) 19 | 20 | # Print the set of mix_colors 21 | print("Mix Colors:", mix_colors) 22 | 23 | # Check if smooth_finish_colors is subset of ultra_sheen_finish_colors set 24 | print("\nIs Smooth Finish a Subset of Ultra Sheen Finish:", smooth_finish_colors.issubset(ultra_sheen_finish_colors)) 25 | 26 | # Check if smooth_finish_colors is subset of mix_colors set 27 | print("\nIs Smooth Finish a Subset of Mix Colors:", smooth_finish_colors.issubset(mix_colors)) 28 | 29 | 30 | """ 31 | Output - 32 | --------------------------------------------------------------- 33 | Smooth Finish Colors: {'Satin Blue', 'Antique White', 'Classic Ivory', 'Silk White'} 34 | Ultra Sheen Finish Colors: {'Satin Blue', 'Glossy Black', 'Metallic Silver'} 35 | Mix Colors: {'Satin Blue', 'Classic Ivory', 'Metallic Silver', 'Silk White', 'Glossy Black', 'Antique White'} 36 | 37 | Is Smooth Finish a Subset of Ultra Sheen Finish: False 38 | 39 | Is Smooth Finish a Subset of Mix Colors: True 40 | 41 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_issuperset_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - issuperset() 3 | 4 | Description: Returns True, if all elements of set A are present in set B. Else, it returns False. 5 | """ 6 | 7 | # Define sets representing different finish options for Asian Paints color products 8 | smooth_finish_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White"} 9 | ultra_sheen_finish_colors = {"Satin Blue", "Glossy Black", "Metallic Silver"} 10 | 11 | mix_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White", "Glossy Black", "Metallic Silver"} 12 | 13 | # Print the set of smooth_finish_colors 14 | print("Smooth Finish Colors:", smooth_finish_colors) 15 | 16 | # Print the set of ultra_sheen_finish_colors 17 | print("Ultra Sheen Finish Colors:", ultra_sheen_finish_colors) 18 | 19 | # Print the set of mix_colors 20 | print("Mix Colors:", mix_colors) 21 | 22 | # Check if smooth_finish_colors is superset of ultra_sheen_finish_colors set 23 | print("\nIs Smooth Finish a Superset of Ultra Sheen Finish:", smooth_finish_colors.issuperset(ultra_sheen_finish_colors)) 24 | 25 | # Check if mix_colors is superset of ultra_sheen_finish_colors set 26 | print("\nIs Mix Colors a Superset of Ultra Sheen Finish:", mix_colors.issuperset(ultra_sheen_finish_colors)) 27 | 28 | 29 | """ 30 | Output - 31 | --------------------------------------------------------------- 32 | Smooth Finish Colors: {'Classic Ivory', 'Silk White', 'Satin Blue', 'Antique White'} 33 | Ultra Sheen Finish Colors: {'Metallic Silver', 'Satin Blue', 'Glossy Black'} 34 | Mix Colors: {'Silk White', 'Classic Ivory', 'Satin Blue', 'Metallic Silver', 'Glossy Black', 'Antique White'} 35 | 36 | Is Smooth Finish a Superset of Ultra Sheen Finish: False 37 | 38 | Is Mix Colors a Superset of Ultra Sheen Finish: True 39 | 40 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_pop_method_example1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - pop() 3 | 4 | Description: Randomly removes an item from a set and returns the removed item. 5 | """ 6 | 7 | # Create a Set of travel destinations in Sri Lanka 8 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa", "Jaffna"} 9 | 10 | # Print the original set of travel destinations 11 | print("Original travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 12 | 13 | # Randomly removing an travel destination from a set 14 | removed_destination = travel_destinations.pop() 15 | 16 | # Printing travel destination which got removed 17 | print("\nTravel Destination removed: {}".format(removed_destination)) 18 | 19 | # Print the updated set of travel destinations 20 | print("\nUpdated travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 21 | 22 | """ 23 | Output - 24 | --------------------------------------------------------------- 25 | Original travel destinations in Sri Lanka: 26 | {'Colombo', 'Mirissa', 'Sigiriya', 'Kandy', 'Jaffna', 'Ella', 'Nuwara Eliya', 'Galle', 'Polonnaruwa'} 27 | 28 | Travel Destination removed: Colombo 29 | 30 | Updated travel destinations in Sri Lanka: 31 | {'Mirissa', 'Sigiriya', 'Kandy', 'Jaffna', 'Ella', 'Nuwara Eliya', 'Galle', 'Polonnaruwa'} 32 | 33 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_pop_method_example2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - pop() 3 | 4 | Description: Randomly removes an item from a set and returns the removed item. 5 | 6 | Scenario: 7 | 8 | Drawing Lottery Prizes - 9 | Imagine you have a group of people participating in a contest, and you want to randomly select winners for prizes. 10 | You can use a set to store the names of participants and 11 | then use the pop() method to randomly select and announce the winners. 12 | """ 13 | 14 | # Create a Set of participants who participated in a lucky draw 15 | participants = {"Alice", "Bob", "Charlie", "David", "Eve"} 16 | 17 | # Print the set of participants 18 | print("Participants: \n{}".format(participants)) 19 | 20 | # Randomly selecting winners for prizes 21 | winner = participants.pop() 22 | 23 | # Printing winning participant 24 | print("\nWinner: {}".format(winner)) 25 | 26 | # Print the names of rest of the participant who will go to the next round 27 | print("\nThe rest of the participants who will go to the next round: \n{}".format(participants)) 28 | 29 | """ 30 | Output - 31 | --------------------------------------------------------------- 32 | Participants: 33 | {'Eve', 'Alice', 'Charlie', 'David', 'Bob'} 34 | 35 | Winner: Eve 36 | 37 | The rest of the participants who will go to the next round: 38 | {'Alice', 'Charlie', 'David', 'Bob'} 39 | 40 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_remove_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - remove() 3 | 4 | Description: Removes the specified element from the set. 5 | 6 | Note: If the element passed to remove() doesn't exist, KeyError exception is thrown. 7 | """ 8 | 9 | # Create a Set of travel destinations in Sri Lanka 10 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 11 | 12 | # Print the original set of travel destinations 13 | print("Original travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 14 | 15 | # Remove a travel destination from set 16 | destination_to_remove = "Polonnaruwa" 17 | 18 | try: 19 | travel_destinations.remove(destination_to_remove) 20 | print("\nRemoved from the travel destinations: {}".format(destination_to_remove)) 21 | except KeyError: 22 | print("\nTravel destinations is not present in set: {}".format(destination_to_remove)) 23 | 24 | # Print the updated set of travel destinations 25 | print("\nUpdated travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 26 | 27 | """ 28 | Output - 29 | --------------------------------------------------------------- 30 | Original travel destinations in Sri Lanka: 31 | {'Polonnaruwa', 'Kandy', 'Nuwara Eliya', 'Galle', 'Ella', 'Colombo', 'Sigiriya', 'Mirissa'} 32 | 33 | Removed from the travel destinations: Polonnaruwa 34 | 35 | Updated travel destinations in Sri Lanka: 36 | {'Kandy', 'Nuwara Eliya', 'Galle', 'Ella', 'Colombo', 'Sigiriya', 'Mirissa'} 37 | 38 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_simple_code.py: -------------------------------------------------------------------------------- 1 | """ 2 | Description: Simple code to declare set and printing it. 3 | """ 4 | 5 | # Set containing Sri Lanka Travel Destinations 6 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 7 | 8 | # Print the set containing Sri Lanka travel destinations 9 | print("Popular travel destinations in Sri Lanka: {}".format(travel_destinations)) 10 | 11 | """ 12 | Output - 13 | --------------------------------------------------------------- 14 | Popular travel destinations in Sri Lanka: {'Nuwara Eliya', 'Ella', 'Mirissa', 'Polonnaruwa', 'Sigiriya', 'Colombo', 'Kandy', 'Galle'} 15 | """ 16 | -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_symmetric_difference_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - symmetric_difference() 3 | 4 | Description: Returns all the items present in given sets, except the items in their intersections. 5 | """ 6 | 7 | # Define sets representing different finish options for Asian Paints color products 8 | smooth_finish_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White"} 9 | ultra_sheen_finish_colors = {"Satin Blue", "Glossy Black", "Metallic Silver"} 10 | 11 | # Print the set of smooth_finish_colors 12 | print("Smooth Finish Colors:", smooth_finish_colors) 13 | 14 | # Print the set of ultra_sheen_finish_colors 15 | print("Ultra Sheen Finish Colors:", ultra_sheen_finish_colors) 16 | 17 | # Find elements that are in either of the sets but not in both 18 | symmetric_diff = smooth_finish_colors.symmetric_difference(ultra_sheen_finish_colors) 19 | 20 | # Print the all the colors present in both color type 21 | print("\nColors that are present in either of the sets but not in both:\n", symmetric_diff) 22 | 23 | 24 | """ 25 | Output - 26 | --------------------------------------------------------------- 27 | Smooth Finish Colors: {'Satin Blue', 'Antique White', 'Silk White', 'Classic Ivory'} 28 | Ultra Sheen Finish Colors: {'Satin Blue', 'Glossy Black', 'Metallic Silver'} 29 | 30 | Colors that are present in either of the sets but not in both: 31 | {'Classic Ivory', 'Antique White', 'Glossy Black', 'Silk White', 'Metallic Silver'} 32 | 33 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_symmetric_difference_update_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - symmetric_difference_update() 3 | 4 | Description: finds the symmetric difference of two sets (non-similar items of both sets) 5 | and updates it to the set that calls the method. 6 | """ 7 | 8 | # Define sets representing different finish options for Asian Paints color products 9 | smooth_finish_colors = {"Satin Blue", "Antique White", "Classic Ivory", "Silk White"} 10 | ultra_sheen_finish_colors = {"Satin Blue", "Glossy Black", "Metallic Silver"} 11 | 12 | # Print the set of smooth_finish_colors 13 | print("Smooth Finish Colors:", smooth_finish_colors) 14 | 15 | # Print the set of ultra_sheen_finish_colors 16 | print("Ultra Sheen Finish Colors:", ultra_sheen_finish_colors) 17 | 18 | # Find elements that are in either of the sets but not in both smooth_finish_colors and ultra_sheen_finish_colors 19 | # Basically find non-similar items in both sets 20 | smooth_finish_colors.symmetric_difference_update(ultra_sheen_finish_colors) 21 | 22 | # Print the all the colors present in smooth_finish_colors set after calling symmetric_difference_update method 23 | print("\nUpdated Smooth Finish Colors Set:\n", smooth_finish_colors) 24 | 25 | 26 | """ 27 | Output - 28 | --------------------------------------------------------------- 29 | Smooth Finish Colors: {'Antique White', 'Classic Ivory', 'Silk White', 'Satin Blue'} 30 | Ultra Sheen Finish Colors: {'Metallic Silver', 'Glossy Black', 'Satin Blue'} 31 | 32 | Updated Smooth Finish Colors Set: 33 | {'Metallic Silver', 'Silk White', 'Classic Ivory', 'Glossy Black', 'Antique White'} 34 | 35 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_union_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - union() 3 | 4 | Description: Returns a new set with distinct elements from all the sets. 5 | """ 6 | 7 | # Define playlists as sets of songs 8 | ed_sheeran_playlist = {"Thinking Out Loud", "Perfect", "Photograph", "Shape of You"} 9 | mix_english_songs_playlist = {"Photograph", "Shape of You", "Too Good At Goodbyes", "Girls Like You", "Faded", "Happier"} 10 | 11 | # Print the set of Ed Sheeran Songs Playlist 12 | print("Ed Sheeran Playlist:", ed_sheeran_playlist) 13 | 14 | # Print the set of Mix English Songs Playlist 15 | print("Mix English Playlist:", mix_english_songs_playlist) 16 | 17 | # Combine playlists using the union method 18 | english_playlist = ed_sheeran_playlist.union(mix_english_songs_playlist) 19 | 20 | # Print the updated set of English Songs Playlist 21 | print("\nCombined Playlist:", english_playlist) 22 | 23 | 24 | """ 25 | Output - 26 | --------------------------------------------------------------- 27 | Ed Sheeran Playlist: {'Thinking Out Loud', 'Shape of You', 'Photograph', 'Perfect'} 28 | Mix English Playlist: {'Happier', 'Faded', 'Girls Like You', 'Too Good At Goodbyes'} 29 | 30 | Combined Playlist: {'Happier', 'Photograph', 'Faded', 'Perfect', 'Thinking Out Loud', 'Too Good At Goodbyes', 'Shape of You', 'Girls Like You'} 31 | 32 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/Session 5.4 - Python Set/set_update_method.py: -------------------------------------------------------------------------------- 1 | """ 2 | Method - update() 3 | 4 | Description: Used to modify a set by adding elements from another iterable (such as a list, tuple, or another set) to the original set. 5 | """ 6 | 7 | # Create a Set of travel destinations in Sri Lanka 8 | travel_destinations = {"Colombo", "Kandy", "Galle", "Sigiriya", "Ella", "Nuwara Eliya", "Mirissa", "Polonnaruwa"} 9 | 10 | # Print the original set of travel destinations 11 | print("Original travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 12 | 13 | # Creating a new_locations set having new travel destination of Sri Lanka 14 | new_locations = {"Jaffna", "Trincomalee", "Hikkaduwa"} 15 | 16 | # Update the set of travel destinations with the new locations 17 | travel_destinations.update(new_locations) 18 | 19 | # Print the updated set of travel destinations 20 | print("\nUpdated travel destinations in Sri Lanka: \n{}".format(travel_destinations)) 21 | 22 | """ 23 | Output - 24 | --------------------------------------------------------------- 25 | Original travel destinations in Sri Lanka: 26 | {'Galle', 'Colombo', 'Mirissa', 'Nuwara Eliya', 'Ella', 'Sigiriya', 'Kandy', 'Polonnaruwa'} 27 | 28 | Updated travel destinations in Sri Lanka: 29 | {'Galle', 'Colombo', 'Mirissa', 'Nuwara Eliya', 'Ella', 'Sigiriya', 'Hikkaduwa', 'Trincomalee', 'Kandy', 'Jaffna', 'Polonnaruwa'} 30 | 31 | """ -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/bash_datatypes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Title: Datatypes in Bash 4 | 5 | # int (Integer): Represents whole numbers without any fractional part. 6 | 7 | printf -- "-----------------------------------------------------------------------------------" 8 | printf "\n\n***************** Examples for Integer Datatype *****************\n\n" 9 | 10 | age=25 11 | printf "Age: ${age}" 12 | 13 | num_students=30 14 | printf "\nNumber of Students: ${num_students}" 15 | 16 | printf -- "\n\n-----------------------------------------------------------------------------------\n" 17 | 18 | # str (String) : Represents a sequence of characters enclosed in single quotes (' ') or double quotes (" "). 19 | 20 | printf "\n***************** Examples for String Datatype *****************\n\n" 21 | 22 | name="John Doe" 23 | printf "Name: ${name}" 24 | 25 | message="Welcome to our website!" 26 | printf "\nMessage: ${message}" 27 | 28 | printf -- "\n\n-----------------------------------------------------------------------------------\n" 29 | 30 | # bool (Boolean): Represents either True or False. It is used in logical operations and conditional statements. 31 | 32 | printf "\n***************** Examples for Boolean Datatype *****************\n\n" 33 | 34 | is_logged_in=True 35 | printf "is_logged_in: ${is_logged_in}" 36 | 37 | is_valid=False 38 | printf "\nis_valid: ${is_valid}" 39 | 40 | printf -- "\n\n-----------------------------------------------------------------------------------\n" 41 | 42 | # array (Arrays): Collections of elements stored in a single variable. Arrays in Bash can contain both strings and integers. You can access individual elements using their indices or iterate over the entire array. 43 | 44 | printf "\n***************** Examples for Array Datatype *****************\n\n" 45 | 46 | # shopping_list[*] for printing all elements of shopping_list 47 | 48 | shopping_list=("apples", "bananas", "milk") 49 | printf "Shopping List: ${shopping_list[*]}" 50 | 51 | grades=(90, 85, 95) 52 | printf "\nGrades: ${grades[*]}" 53 | 54 | printf -- "\n\n-----------------------------------------------------------------------------------\n" 55 | 56 | # Dictionary (Associative Array): An associative array called dictionary with key-value pairs. 57 | 58 | printf "\n***************** Examples for Dictionary (Associative Array) Datatype *****************\n\n" 59 | 60 | declare -A person 61 | person["name"]="John" 62 | person["age"]=30 63 | person["city"]="New York" 64 | 65 | printf "Person: " 66 | declare -p person 67 | 68 | printf "\nPerson Name: ${person["name"]}\n\n" 69 | 70 | declare -A product 71 | product["name"]="Phone" 72 | product["price"]=599 73 | product["brand"]="Apple" 74 | 75 | printf "Product: " 76 | declare -p product 77 | 78 | printf "\nProduct Brand: ${product["brand"]}" 79 | 80 | printf -- "\n\n-----------------------------------------------------------------------------------\n" -------------------------------------------------------------------------------- /Session 5 - Datatypes in Python and Shell-Bash Scripting/python_datatypes.py: -------------------------------------------------------------------------------- 1 | # Title: Datatypes in Python 2 | 3 | # int (Integer): Represents whole numbers without any fractional part. 4 | 5 | print("-----------------------------------------------------------------------------------") 6 | print("\n***************** Examples for Integer Datatype *****************\n") 7 | 8 | age = 25 9 | print("Datatype for age variable: {}\n".format(type(age))) 10 | print("Age: {}".format(age)) 11 | 12 | num_students = 30 13 | print("\nNumber of Students: {}".format(num_students)) 14 | 15 | print("\n-----------------------------------------------------------------------------------\n") 16 | 17 | # str (String) : Represents a sequence of characters enclosed in single quotes (' ') or double quotes (" "). 18 | 19 | print("***************** Examples for String Datatype *****************\n") 20 | 21 | name = "John Doe" 22 | print("Datatype for name variable: {}".format(type(name))) 23 | print("Name: {}".format(name)) 24 | 25 | message = "Welcome to our website!" 26 | print("\nMessage: {}".format(message)) 27 | 28 | print("\n-----------------------------------------------------------------------------------\n") 29 | 30 | # bool (Boolean): Represents either True or False. It is used in logical operations and conditional statements. 31 | 32 | print("***************** Examples for Boolean Datatype *****************\n") 33 | 34 | is_logged_in = True 35 | print("Datatype for is_logged_in variable: {}".format(type(is_logged_in))) 36 | print("is_logged_in: {}".format(is_logged_in)) 37 | 38 | is_valid = False 39 | print("\nis_valid: {}".format(is_valid)) 40 | 41 | print("\n-----------------------------------------------------------------------------------\n") 42 | 43 | # list (List): Represents an ordered collection of items enclosed in square brackets ([]). The items can be of different data types. 44 | 45 | print("***************** Examples for List Datatype *****************\n") 46 | 47 | shopping_list = ['apples', 'bananas', 'milk'] 48 | print("Datatype for shopping_list variable: {}".format(type(shopping_list))) 49 | print("Shopping List: {}".format(shopping_list)) 50 | 51 | grades = [90, 85, 95] 52 | print("\nGrades: {}".format(grades)) 53 | 54 | print("\n-----------------------------------------------------------------------------------\n") 55 | 56 | # tuple (Tuple): Similar to a list, but it is immutable, meaning its elements cannot be changed after creation. It is represented by items enclosed in parentheses (()). 57 | 58 | print("***************** Examples for Tuple Datatype *****************\n") 59 | 60 | point = (2, 5) 61 | print("Datatype for point variable: {}".format(type(point))) 62 | print("Point: {}".format(point)) 63 | 64 | color = (255, 0, 0) 65 | print("\nColor: {}".format(color)) 66 | 67 | print("\n-----------------------------------------------------------------------------------\n") 68 | 69 | # dict (Dictionary): Represents a collection of key-value pairs enclosed in curly braces ({ }). Each key is unique and associated with a value. 70 | 71 | print("***************** Examples for Dictionary Datatype *****************\n") 72 | 73 | person = {'name': 'John', 'age': 30, 'city': 'New York'} 74 | print("Datatype for person variable: {}".format(type(person))) 75 | print("Person: {}".format(person)) 76 | 77 | product = {'name': 'Phone', 'price': 599, 'brand': 'Apple'} 78 | print("\nProduct: {}".format(product)) 79 | 80 | print("\n-----------------------------------------------------------------------------------\n") 81 | 82 | # set (Set): Represents an unordered collection of unique elements. It is enclosed in curly braces ({ }). 83 | 84 | print("***************** Examples for Set Datatype *****************\n") 85 | 86 | email_set = {'user1@example.com', 'user2@example.com', 'user3@example.com'} 87 | print("Datatype for email_set variable: {}".format(type(email_set))) 88 | print("email_set: {}".format(email_set)) 89 | 90 | tags = {'python', 'programming', 'tutorial'} 91 | print("\nTags: {}".format(tags)) 92 | 93 | print("\n-----------------------------------------------------------------------------------\n") 94 | --------------------------------------------------------------------------------