This post is the first part of a series on Advanced Python. In this series, we’ll take what we learned in our Understanding Python Basic series (Part One of that series found here) and expand on it to understand the more challenging parts of Python. In Part 1, you’ll be learning about advanced uses of the Dictionaries and maps used in Python. Part 2, which explores Conditions in Python, can be found here.
If you want to use the Nexus as your Python editor, then you will find instructions at the end of the blog on how to set this up!
You are about to go on a journey in the data jungle looking for python. I am going to make this lesson safe, fun, and educational. My goal is to build your confidence with the basics of Python so you will be ready to take your knowledge even deeper.
If you have a Python editor you want to use then you are all ready to go, but if you want an easy way to try these examples and more then go to www.CoffingDW.com and download the Nexus. Once you have it installed just look at the picture below and see where the Python editor of Nexus exists. If you want to install Python so you can practice with Nexus then go to the last page of this blog for detailed instructions.
Creating a Tuple
A Tuple is a list of values that cannot be changed. That means it is immutable. You can change a list (mutable), but not a Tuple. The Tuple uses ( ) round braces when created, but a list uses [ ] square brackets. Why would you use a tuple instead of a list? So, you can be assured that the tuple can’t be changed. If you create a tuple with four elements inside, it will always have four elements inside. Consider a list written in pencil, but a tuple written in stone!
A Tuple is a list of values that cannot be changed. You can change a list, but not a Tuple. Our examples show us how to get the number of values, the first value and the last value in the tuple using the ‘len’, ‘min’ and ‘max’ commands.
Creating Dictionaries or Maps
A Dictionary/Map is made up of values with a unique key for each value stored. A dictionary or map (interchangeable terms) are similar to lists, but you can’t join a dictionary or map using a + sign like you can a list.
Finding Individual Entries in Dictionaries/Maps
The example below shows how to get the value for a unique key in our dictionary. We put in ‘California’ (key) and it returns the state capital value of ‘Sacramento’.
Finding Individual Entries in Dictionaries/Maps Using Get
Our example below shows how to get the value for a unique key in our dictionary. We put in ‘Alaska’ (key) with the keyword ‘get’ and it returns the state capital value of ‘Juneau’.
Deleting Entries in Dictionaries/Maps
Our example below shows how to delete a value from our dictionary. We put in the delete command (del) and we are deleting the ‘California’ (key). After the delete, both ‘California’ and ‘Sacramento’ are no longer in the dictionary.
How Many Entries are in my Dictionary/Map?
Our examples show us how to get the number of values, the first value and the last value in the map using the ‘len’, ‘min’ and ‘max’ commands.
Modify/Update Entries in Dictionaries/Maps
Our example below shows how to update a value from our dictionary. We are changing the capital of ‘Arkansas’ from ‘Little Rock’ to ‘Big Rock’.
Getting a list of Keys in Dictionaries/Maps
Our example below shows how to get a list of the unique keys in our dictionary or map.
Tips – Creating a Dictionary from Two Related Sequences
You can create a dictionary from two related sequences. Notice we have five entries in both t1 and t2. Positionally, they become a pair in our dictionary.
Tips – Dictionary/Set Comprehensions
This is an example of how to use dictionary/set comprehensions. They are simple, but yet powerful and effective.
- Download the latest version of Nexus from our website. https://www.coffingdw.com/nexus-trial/
- Once installed download Python for Windows. https://www.python.org/downloads/windows/
Your version number can vary, but you will want to download the Windows installers. So for Python for Windows 3.7.3 located here (https://www.python.org/downloads/release/python-373/) you will select one of these highlighted links:
Note: Nexus comes in three versions: Nexus 64-bit, Nexus 32-bit, and Nexus WOW-64 (For 64-bit machines with 32-bit Microsoft Office installed).X86-64 can be used for the 64-bit or Wow64 version of Nexus and x86 can be used only on the 32-bit version of Nexus.
When installing, if you have the option, select “Add Python to PATH”.
If you are using an older version of Python and do not have this option, then you will need to add the path to your python executable to your PATH environment variable. Be careful when editing this variable as it can affect many Windows functionality issues. If you don’t feel comfortable about this then consult with your desktop support.
Python 3.7.3 was installed in the following directory on our PC.
You can view your Python directory by opening File Explorer and pasting in the following path:
Once you have the path to the python.exe executable then add it to your Environment PATH variable by following the direction in this link:
And that is how you install Python into the Nexus Query Chameleon!
Ready for more Python training? Check out Part Two of my Understanding Advanced Python series! Or, if you’d prefer Tera-Tom to come teach at your organization, contact our team for booking information.