Giter Site home page Giter Site logo

python-p3-intro-to-data-structures's Introduction

Intro to Data Structures

Learning Goals

  • Understand what a data structure is and how they are used in Python.
  • Learn which types of tasks data structures are used to solve.

Key Vocab

  • Sequence: a data structure in which data is stored and accessed in a specific order.
  • Index: the location, represented by an integer, of an element in a sequence.
  • Iterable: able to be broken down into smaller parts of equal size that can be processed in turn. You can loop through any iterable object.
  • Slice: a group of neighboring elements in a sequence.
  • Mutable: an object that can be changed.
  • Immutable: an object that cannot be changed. (Many immutable objects appear mutable because programmers reuse their names for new objects.)
  • List: a mutable data type in Python that can store many types of data. The most common data structure in Python.
  • Tuple: an immutable data type in Python that can store many types of data.
  • Range: a data type in Python that stores integers in a fixed pattern.
  • String: an immutable data type in Python that stores unicode characters in a fixed pattern. Iterable and indexed, just like other sequences.

Introduction

Data is information that has been standardized in such a way that it is useful to the individual or machine that is working with it. Everything that you see on your computer screen right now is composed of data. The letters in this paragraph, the colors on this page, the links and buttons that navigate to and from resources on the internet- all data.

In Python Fundamentals, we talked about the importance of organizing our code for other humans to be able to read. After all, a foolish consistency is the hobgoblin of little minds. Data structures are a way for us to organize data in a way that is easy for computers to read.


Why Don't We Just Put Everything in a List?

list objects are very useful for storing data in Python, but there are many situations where a computer would want data stored in a different way.

To provide some perspective, let's compare a list with a set:

list set
    Can store all types of data.
    Indexed - Each item in a list has a set location.
    Mutable - Can be extended or converted to another data type.
    Items can be repeated.
    Items can be changed or replaced.
    Can store all types of data.
    Unindexed - Items in a set are stored using an item's name.
    Mutable - Can be extended or converted to another data type.
    Items are unique.
    Items cannot be changed or replaced.

There are a number of similarities here, and it's clear that list objects are much more flexible than set objects. But if we're looking for which items exist rather than how many, a data structure with unique items that allows us to access them by name rather than index is more useful. Lucky for us, Python provides the set data structure out of the box!


Types of Data Structures in Python

Python gives us access to a number of different data structures to help us communicate with our computers. Some are built-in data types while others require a little more work to set up.

Data Types that are Data Structures

  • Sequences:
    • list
    • tuple
    • str
  • Sets:
  • Maps:
    • dict (the only map type in Python!)

* We won't be covering these in our curriculum, but they may be useful to you in advanced computing contexts

Trees and Linked Lists

Python does not come with every data structure built into its data types, but the standard library includes several modules and packages that help us build out more complex data structures. Trees and linked lists are two of the most common. We'll discuss these later on in Phase 3.

Be sure to check out the resources below as well, and bookmark them for future reference!


Resources

python-p3-intro-to-data-structures's People

Contributors

professor-ben avatar lizbur10 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.