Programming Languages

Module 2: Python Data Structures

Learning Objectives:

  • To be able to recognize the various components and keywords of a programming language
  • To be able to create simple programs and understand the basics of Python syntax.
  • To be able to use Python for data analysis.
  • To be able to use Python for machine learning and artificial intelligence.

Introduction

MBA students need to understand Python data structures. Having a strong understanding of Python data structures will give MBA students the skills they need to understand how data works in their projects and make better decisions. Data structures are an essential part of any programming language and are necessary for being able to efficiently store, process, analyze, and report data. Knowing how to use and manipulate data is quickly becoming an essential skill that all MBA students need to have. 

Discussion of Python Data Structures

  • Lists and Tuples
  • Sets / Dictionaries

Lists and Tuples

Lists and tuples are compound data types and are an integral part of Python.

Tuples are an ordered, immutable collection of items grouped into a single unit. For example, if you had a Tuple named "Ratings," then the values contained in it would be expressed as comma-separated elements shown within parentheses. These values can consist of Python's many data types, such as strings, integers, and floats.

A list is an ordered sequence that can contain different python data types such as strings, floats, and integers. It is also mutable; this means we can modify it once created.

Thus, lists differ from tuples in that they are mutable, meaning their values can be updated or shortened.

Sets

Sets are a type of collection in Python. Unlike lists and tuples, however, they are unordered which means they do not record element position. Furthermore, sets only have unique elements; there can only be one of any particular items in a set. It is often helpful to illustrate how two sets interact using Venn diagrams. The intersection of two sets is a new set comprised of the shared elements that appear in both circles. Similarly, the union of two sets contains all the items from each set combined into one.

Dictionaries

Dictionaries are an important type of collection in the Python programming language. Unlike lists, dictionaries do not use integer indexes as "addresses"; rather, they rely on keys which can be any character string. For each key, a value is assigned; the value can be anything from a simple variable to a complex object like a list or another dictionary. Furthermore, the values can be either mutable or immutable and may have duplicates within the same dictionary. Overall, each key-value pair is separated by a comma allowing for easy access to all data stored in the dictionary.

Conclusion

Python data structures are important because they allow you to store and manipulate data. The most common data structures in Python are lists, tuples, dictionaries, and sets. These Python data structures are powerful tools for handling and organizing data. They are also efficient, allowing you to work with large amounts of data quickly and efficiently. For those who are new to programming, learning how to use Python data structures can be a great way to start.

Discussion of Python Data Structures

  • Lists and Tuples
  • Sets / Dictionaries