Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Treehouse

Python List Comprehensions

via Treehouse

Overview

Learn to write more efficient and concise code using Python list comprehensions. Explore the syntax and structure of list comprehensions, as well as best practices for using them to filter, map, and manipulate data in a single line of code. By the end, apply list comprehensions to solve complex programming problems and write cleaner, more efficient Python code.

Syllabus

Treehouse: HTML, CSS, PHP, JS, and Python Development Courses header, footer, .graph, .nav, svg { display: none } window.dataLayer = window.dataLayer || []; dataLayer.push({"loggedIn":false,"visitorId":8364008398,"userId":null}); (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl+'';f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PZ55S7'); window.bugsnagClient = bugsnag({ apiKey: "8251a8eb6422d59eaf410e7c1b1c7b38", releaseStage: "production", beforeSend: function (report) { if (window.location.hostname != "teamtreehouse.com") { report.ignore(); } } }); function OptanonWrapper() { window.dataLayer.push({ event: "OneTrustGroupsUpdated" }) } // .nav-announcement { background-color: #64ce83; height: 40px; position: fixed; display : flex; align-items : center; justify-content : center; top: 0; left: 0; right: 0; z-index: 5000; padding: 0 10px; word-break: break-word; } .nav-announcement h6 { text-align: center; font-size: 13px; color: #ffffff !important; } .nav-announcement a { color: #ffffff; font-size: 13px; line-height: 16px; text-decoration: underline; } .nav-announcement a:hover { color: #0e8397; } .nav-announcement p { color: #ffffff; font-size: 12px; line-height: 15px; font-weight: 500; margin-bottom: 0; text-align: center; } function navMessage(x) { var navAnnouncement = document.getElementsByClassName("nav-announcement"); if (navAnnouncement.length > 0) { if (x.matches) { // If media query matches navAnnouncement[0].innerHTML = '

Earn a Techdegree. Change your career and your life. ' } else { navAnnouncement[0].innerHTML = 'Have you checked out new workshop How to Set Up a React App yet?' } } } var x = window.matchMedia("(max-width: 1124px)") navMessage(x); x.addListener(navMessage);

  • Home
  • Free Trial
  • Sign In
  • Plans
  • Tracks
  • Library
  • Community
  • Support
  • Jobs

Welcome to the Treehouse Library

This is a sample catalog of all the courses we offer. Browse by topic or difficulty. Sign up today and get access to our entire library. Treehouse students get access to workshops, bonus content, conferences, and more.

Ready to start learning?

Treehouse offers a 7 day free trial for new students. Get access to 1000s of hours of content. Learn to code, land your dream job.

Start Your Free Trial Filters:
  • Newest
    • Newest
    • Oldest
    • Alphabetical
    • Difficulty
  • Content type
    • All Types
    • Course
    • Workshop
    • Practice
    • Conference
    • Bonus Series
  • All Topics
    • All Topics
    • • JavaScript
    • • Python
    • • Design
    • • HTML
    • • CSS
    • • Data Analysis
    • • Java
    • • Databases
    • • C#
    • • Android
    • • Computer Science
    • • PHP
    • • Quality Assurance
    • • APIs
    • • Security
    • • Digital Literacy
    • • Development Tools
    • • Business
    • • 21st Century Skills
    • • Ruby
    • • Machine Learning
    • • Learning Resources
    • • Go
    • • Equity, Diversity, and Inclusion (EDI)
View all Tracks

Popular Tracks

These are some of the most common tracks students start with.

    55 hours

    Track

    Front End Web Development

    Learn to code websites using HTML, CSS, and JavaScript.

    • Explore
    • Play
    • An entry-level salary for the technologies covered in this track is about $51,000 / yr on average.

    • Some companies that use these technologies regularly include: Google, Facebook, Yahoo, eBay, Amazon, and Treehouse.

    14 hours

    Track

    Beginning Python

    Learn the general purpose programming language Python and build large and small applications and tools.

    • Explore
    • Play
    • An entry-level salary for the technologies covered in this track is about $70,000 / yr on average.

    • Some companies that use these technologies regularly include: Google, NASA, Nokia, IBM, Digg, Dropbox, Pinterest, Reddit, Yelp, Apple, and Amazon.

    41 hours

    Track

    Full Stack JavaScript

    Learn JavaScript, Node.js, and Express to become a professional JavaScript developer.

    • Explore
    • Play
    • An entry-level salary for the technologies covered in this track is about $65,000 / yr on average.

    • Some companies that use these technologies regularly include: Walmart, PayPal, Groupon, Airbnb.

Topics

Browse content by the topics that interest you most.

  • JavaScript
  • Python
  • Design
  • HTML
  • CSS
  • Data Analysis
  • Java
  • Databases
  • C#
  • Android
  • Computer Science
  • PHP
  • Quality Assurance
  • APIs
  • Security
  • Digital Literacy
  • Development Tools
  • Business
  • 21st Century Skills
  • Ruby
  • Machine Learning
  • Learning Resources
  • Go
  • Equity, Diversity, and Inclusion (EDI)

Change Your Career, Change Your Life

With 100s of courses and more to come, Treehouse is the best way to learn how to code.

Start Your Free Trial View all 285

Courses

Browse courses across an array of topics and disciplines.

    • 1
    • 2
    • 3
    • 4
    2 hours Course

    Introduction to HTML and CSS

    | 87463 students

    Get started creating web pages with HTML and CSS, the basic building blocks of web development. HTML, or HyperText Markup Language, is a standard set of tags you will use to tell the web browser how the content of your web pages and applications are structured. Use CSS, or Cascading Style Sheets, to select HTML tags and tell the browser what your content should look like. Whether you are coding for fun or planning to start a career in web development, learning HTML and CSS is a great place to start.

    Checkmark
    • HTML
    • Beginner
      • 1
      • 2
      • 3
      • 4
      3 hours Course

      JavaScript Basics

      | 21416 students

      JavaScript is a programming language that drives the web: from front-end user interface design to server-side backend programming, you'll find JavaScript at every stage of a website and web application. In this course, you'll learn the fundamental programming concepts and syntax of the JavaScript programming language.

      Checkmark
      • JavaScript
      • Beginner
        • 1
        • 2
        • 3
        • 4
        3 hours Course

        HTML Basics

        | 49641 students

        Learn HTML (HyperText Markup Language), the language common to every website. HTML describes the basic structure and content of a web page. If you want to build a website or web application, you'll need to know HTML.

        Checkmark
        • HTML
        • Beginner
          • 1
          • 2
          • 3
          • 4
          3 hours Course

          Python Basics

          | 24131 students

          Learn the building blocks of the wonderful general purpose programming language Python.

          Checkmark
          • Python
          • Beginner
            • 1
            • 2
            • 3
            • 4
            3 hours Course

            CSS Basics

            | 8923 students

            In this course, we're going to learn the basics of CSS, one of the core technologies for designing and building websites and applications. No matter what kind of website or web application you want to build, you'll have to use CSS. If you haven't written much CSS, or even if you’ve never written CSS at all, don’t worry. That's what this course is for. We’ll start with basic CSS concepts, then gradually progress to more advanced topics and lessons.

            Checkmark
            • CSS
            • Beginner
              • 1
              • 2
              • 3
              • 4
              2 hours Course

              CSS Layout

              | 7027 students

              In this course, we're going to learn techniques for better control over our CSS layouts. We’ll cover how the CSS Box Model impacts the presentation of each HTML element, learn to control the position of each element onscreen, and even begin to adjust our layouts for different screen sizes and environments.

              Checkmark
              • CSS
              • Beginner
                • 1
                • 2
                • 3
                2 hours Course

                JavaScript and the DOM

                | 3773 students

                JavaScript lets you create interactive web pages which can respond to a user's actions. In this course, you'll learn how to bring web pages to life using the power of JavaScript.

                Checkmark
                • JavaScript
                • Beginner
                  • 1
                  • 2
                  • 3
                  • 4
                  2 hours Course

                  React Basics

                  | 8185 students

                  React is a JavaScript library for building user interfaces. React makes building and maintaining your application's user interface faster and easier by breaking it up into smaller, reusable components. It also helps eliminate the complexity of updating your DOM elements when the user interacts with your application.

                  Checkmark
                  • JavaScript
                  • Intermediate
                    • 1
                    • 2
                    • 3
                    2 hours Course

                    SQL Basics

                    | 28060 students

                    In SQL Basics, we’ll take a look at what databases are and how you can retrieve information from them. Databases can store massive amounts of information to be retrieved at a later date. Databases act as the memory for dynamic web sites or mobile apps.

                    Checkmark
                    • Databases
                    • Beginner
                      • 1
                      • 2
                      • 3
                      • 4
                      68 min Course

                      Node.js Basics

                      | 611 students

                      In this course we will create two command line applications using the popular server-side JavaScript platform Node.js. We'll be creating an application to retrieve a student's Treehouse profile information and be working with a dictionary API to retrieve definitions of a given word.

                      Checkmark
                      • JavaScript
                      • Intermediate
                        • 1
                        • 2
                        • 3
                        3 hours Course

                        Introduction to Git

                        | 10721 students

                        Git is a version control system - it helps you manage the different versions of your project files, and helps keep your work safe. This course will show you how Git works, and how to upload your projects to GitHub.

                        Checkmark
                        • Dev Tools
                        • Beginner
                          • 1
                          • 2
                          • 3
                          • 4
                          • 5
                          3 hours Course

                          C# Basics

                          | 3270 students

                          C# is the most popular programming language in the Microsoft ecosystem of products. C# code is designed to run fast and to be easily maintainable. In C# Basics, we'll learn how to work with C# to write simple programs.

                          Checkmark
                          • C#
                          • Beginner
                          View all 237

                          Workshops

                          Technology-focused presentations of tips, tricks, and tutorials.

                          • 9 min Workshop

                            JavaScript Search

                            Letting users search through data in your application or website is a great UX feature. Building out this type of functionality isn't as hard as you may think. With some basic JavaScript, we can tackle the filtering and searching of data. Follow along as I add a search feature with vanilla JavaScript that allows the user to search for a specific author in a list of authors!

                            CheckmarkViewed
                            • JavaScript
                            • Beginner
                            • 2 min Workshop

                              Shorten Text With CSS

                              Ever wondered how to shorten text with an ellipsis (...)? It’s quite easy to do and only requires a few lines of CSS. Follow along as I take you through setting this up!

                              CheckmarkViewed
                              • CSS
                              • Beginner
                              • 3 min Workshop

                                HTML-Only Accordion

                                Accordions are all over the web and mobile apps. They are a great way to show and hide content based on user interaction and aren’t very hard to build. However, they usually require a bit of HTML, CSS, and JavaScript. Did you know you can build a simple accordion with only HTML in seconds? Follow along as I explain how to set this up!

                                CheckmarkViewed
                                • HTML
                                • Beginner
                                • 8 min Workshop

                                  Full Stack JavaScript Techdegree Portfolio Overview

                                  Here at Treehouse, we have many Techdegrees to get you job ready no matter your skill level. The Full Stack JavaScript Techdegree is one of the most popular. Come take a look at all the professional-quality projects you'll build in this Techdegree!

                                  Start your free trial today! (https://trhou.se/3I1UNT3)

                                  Projects Random Quote Generator (https://teamtreehouse.com/library/introducing-the-random-quote-generator-2) Data Pagination and Filtering (https://teamtreehouse.com/library/introducing-the-data-pagination-and-filtering-project-2) Interactive Form (https://teamtreehouse.com/library/introducing-the-interactive-form-project-2) OOP Game Show App (https://teamtreehouse.com/library/introducing-the-oop-game-show-app-2) Public API Requests (https://teamtreehouse.com/library/introducing-the-api-requests-project-2) Static Node.js and Express Site (https://teamtreehouse.com/library/introducing-the-static-nodejs-and-express-site-project-2) React Gallery App (https://teamtreehouse.com/library/introducing-the-react-gallery-app-project-2) SQL Library Manager (https://teamtreehouse.com/library/introducing-the-sql-library-manager-project-2) REST API (https://teamtreehouse.com/library/introducing-the-rest-api-project-2) Full Stack App with React and a REST API (https://teamtreehouse.com/library/introducing-the-full-stack-app-with-react-and-a-rest-api-project-2)

                                  CheckmarkViewed
                                  • JavaScript
                                  • Beginner
                                  View all 104

                                  Practice

                                  Refine and strengthen your skills with these practice exercises.

                                  • practiceIcon Copy 5 Created with Sketch.
                                    • 1
                                    19 min Practice

                                    Practice Classes in JavaScript

                                    | 8235 students

                                    Practice building and working with classes in JavaScript.

                                    Checkmark
                                    • JavaScript
                                    • Intermediate
                                    • practiceIcon Copy 5 Created with Sketch. 11 min Practice

                                      Practice Setting Up a Python Project

                                      Practice setting up a Python project locally and on GitHub.

                                      CheckmarkViewed
                                      • Python
                                      • Intermediate
                                      • practiceIcon Copy 5 Created with Sketch. 11 min Practice

                                        Practice Hooks in React

                                        Practice React's built-in useContext and useState Hooks to update an app with user authentication.

                                        CheckmarkViewed
                                        • JavaScript
                                        • Intermediate
                                        View all 3

                                        Conferences

                                        Watch talks from influential industry leaders.

                                        • 12 hours Conference

                                          Treehouse Festival July 2020

                                          Treehouse Festival 2020

                                          CheckmarkViewed
                                          • 8 topics
                                            • Computer Science
                                            • HTML
                                            • Design
                                            • Dev Tools
                                            • Digital Literacy
                                            • Learning Resources
                                            • Equity, Diversity, and Inclusion (EDI)
                                            • 21st Century Skills
                                          • 12 hours Conference

                                            Treehouse Festival December 2020

                                            Treehouse Festival is an online conference designed for Treehouse students and all aspiring developers and designers. The presentations will empower those that attend with skills and a network to transition to a tech career or level-up in their current roles. Sessions include “Designing with a Developer Mindset,” “Computer Science, Emulation, and the NES,” “Interview with a Treehouse Grad”, and more!

                                            CheckmarkViewed
                                            • 9 topics
                                              • Design
                                              • HTML
                                              • CSS
                                              • JavaScript
                                              • Dev Tools
                                              • Digital Literacy
                                              • Computer Science
                                              • Equity, Diversity, and Inclusion (EDI)
                                              • 21st Century Skills
                                            • 14 hours Conference

                                              Treehouse Festival June 2021

                                              Treehouse Festival is an online conference designed for Treehouse students and all aspiring developers and designers. The presentations will empower those that attend with skills and a network to transition to a tech career or level-up in their current roles. Sessions include “Designing with a Developer Mindset,” “Computer Science, Emulation, and the NES,” “Interview with a Treehouse Grad”, and more!

                                              CheckmarkViewed
                                              • 12 topics
                                                • Computer Science
                                                • HTML
                                                • CSS
                                                • Design
                                                • Dev Tools
                                                • Business
                                                • Python
                                                • Digital Literacy
                                                • Databases
                                                • Data Analysis
                                                • Equity, Diversity, and Inclusion (EDI)
                                                • 21st Century Skills
                                              View all 24

                                              Bonus Series

                                              Bonus material is exclusive to Courses Plus membership and includes series covering new processes in design, development and illustration.

                                              • 9 min Bonus Series

                                                Takeaways

                                                Got some time during your lunch break? Want to get something to takeaway?

                                                CheckmarkViewed
                                                • 2 topics
                                                  • Java
                                                  • Go
                                                • 119 min Bonus Series

                                                  How to Land Your Dream Job

                                                  How to Land Your Dream Job is a interview series hosted by Treehouse Founder and CEO Ryan Carson. In this series Ryan talks with guests about how they successfully transitioned to tech as a career.

                                                  CheckmarkViewed
                                                  • 21st Century Skills
                                                  • 2 hours Bonus Series

                                                    Hour With a Tech Recruiter

                                                    Ever wonder what Tech Recruiters are looking for when applying to jobs? Welcome to Hour with a Tech Recruiter! In this live event, Treehouse Founder and CEO Ryan Carson will facilitate a conversation with a real world Tech Recruiter. They'll discuss practical tips for folks looking to stand out to recruiters and land a dream job in tech.

                                                    CheckmarkViewed
                                                    • Equity, Diversity, and Inclusion (EDI)
                                                    • 3 hours Bonus Series

                                                      Treehouse Live

                                                      Enjoy our full collection of Treehouse Live sessions with our amazing Treehouse Instructors! Follow along as they teach live and take questions from students like you.

                                                      CheckmarkViewed
                                                      • Learning Resources

                                                      Upcoming Releases

                                                      The following items are scheduled to be released soon. You can also visit our content roadmap for more info.

                                                      • Workshop

                                                        Python Virtual Environments

                                                        If you're building apps with Python, you'll most likely be using third-party libraries and therefore need to use a virtual environment. This workshop will explain what Python virtual environments are. Then, you'll learn to use the venv tool to work with virtual environments, and how to install packages specific to your project. Finally, you'll learn how to replicate your virtual environments with others, such as fellow students, clients, or your development team. You will finish the workshop with a solid understanding of how to use virtual environments to maintain project dependencies and avoid conflicts with other Python projects.

                                                        CheckmarkViewed
                                                        • Python
                                                        • May 2023
                                                        • Workshop

                                                          Build an AI Image Generator with Vanilla JavaScript

                                                          In this video, we'll be building an AI image generator using JavaScript and the ChatGPT API. We'll start by creating a simple interface with a text box where the user can input a description of an image they want to generate. Then, using the power of the ChatGPT API, we'll process the user's input and generate a unique image based on the input. By the end of this video, you'll have a better understanding of how to integrate AI technologies into your web applications and create dynamic, personalized experiences for your users. Join us as we explore the exciting world of AI image generation and learn how to build your own app from scratch.

                                                          CheckmarkViewed
                                                          • Digital Literacy
                                                          • May 2023
                                                          • Workshop

                                                            Build a ChatGPT Discord Bot

                                                            In this tutorial video, Dustin will guide you through the process of building a ChatGPT-powered Discord bot. You'll learn how to create a bot that listens to messages in a designated channel, sends those messages to the ChatGPT API for processing, and then responds with the generated text from the AI. By the end of this tutorial, you'll have a functional Discord bot that can generate responses to user messages using the power of ChatGPT. So whether you're a seasoned developer or just starting out, come join Dustin and learn how to build a ChatGPT Discord bot today!

                                                            CheckmarkViewed
                                                            • Digital Literacy
                                                            • June 2023
                                                            • Workshop

                                                              Python List Comprehensions

                                                              This workshop will teach you how to write more efficient and concise code using Python List Comprehensions. So far, you may have been creating Lists from other Lists by using loops. Python list comprehensions allow for creating new lists based on existing lists, with the ability to filter, map, and manipulate data in a single line of code. You will learn the syntax and structure of list comprehensions, as well as best practices for using them in real-world projects. By the end of the course, you will be able to apply list comprehensions to solve complex programming problems and write cleaner, more efficient code.

                                                              CheckmarkViewed
                                                              • Python
                                                              • June 2023
                                                                • Course

                                                                  Python Dates and Times

                                                                  As a Python developer, you will inevitably come across the need to use dates and times in your projects. This course will teach you how to use Python to work with dates and times. You will learn how to manipulate and format dates, calculate time differences, and explore the built-in datetime module. By the end of this course, you will have a solid understanding of how to handle dates and times in Python for a variety of applications. Throughout this course, we'll work together to build a simple app that will utilize this new concept and solidify your understanding.

                                                                  Checkmark
                                                                  • Python
                                                                  • August 2023
                                                                    • Course

                                                                      React Basics (Refresh 2023)

                                                                      React is a JavaScript library for building user interfaces. React makes building and maintaining your application's user interface faster and easier by breaking it up into smaller, reusable components. It also helps eliminate the complexity of updating your DOM elements when the user interacts with your application.

                                                                      Checkmark
                                                                      • JavaScript
                                                                      • August 2023

                                                                        Treehouse

                                                                      • About
                                                                      • Blog
                                                                      • Careers
                                                                      • Community
                                                                      • Stories
                                                                      • Shop
                                                                      • Contact
                                                                      • Gift Card

                                                                      See Full Catalogue

                                                                      Techdegree

                                                                      • Front End Web Development
                                                                      • Full Stack JavaScript
                                                                      • Python Development
                                                                      • Data Analysis
                                                                      • UX Design

                                                                      Tracks

                                                                      • Learn to Code for Beginners
                                                                      • Beginning Python
                                                                      • Beginning SQL
                                                                      • Beginning Java
                                                                      • ...see more

                                                                      Courses

                                                                      • JavaScript Basics
                                                                      • Intro to HTML & CSS
                                                                      • Python Basics
                                                                      • CSS Layout
                                                                      • ...see more

                                                                      Explore

                                                                      • Plans
                                                                      • Perks
                                                                      • Public Library Access
                                                                      • Treehouse for Libraries
                                                                      • Treehouse for Businesses
                                                                      • Twitter
                                                                      • YouTube
                                                                      • Facebook
                                                                      • LinkedIn
                                                                      • Instagram
                                                                      Terms & Conditions | Privacy

                                                                      © 2023 Treehouse Island, Inc.

                                                                      !function(){ var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t

                                                                      Taught by

                                                                      Rachel Johnson

                                                                      Reviews

                                                                      Start your review of Python List Comprehensions

                                                                      Never Stop Learning.

                                                                      Get personalized course recommendations, track subjects and courses with reminders, and more.

                                                                      Someone learning on their laptop while sitting on the floor.