Coder Social home page Coder Social logo

python_lists's Introduction

INTRODUCTION TO LISTS

Review

So far, we have learned:

  • How to create a list
  • How to access, add, remove, and modify list elements
  • How to create a two-dimensional list
  • How to access and modify two-dimensional list elements

Let’s practice these skills.

Instructions

  1. Maria is entering customer data for her web store business. We’re going to help her organize her data.

    Start by turning this list of customer first names into a list called first_names. Make sure to enter the names in this order:

    • Ainsley
    • Ben
    • Chani
    • Depak
  2. Maria wants to track all customer’s preferred sizes for her clothing. Create a list called preferred_size.

    Fill our new list preferred_size with the following data, containing the preferred sizes for Ainsley, Ben, and Chani:

    ["Small", "Large", "Medium"]
  3. Oh no! We forgot to add Depak’s size.

    Depak’s size is "Medium". Use .append() to add "Medium" to the preferred_size list.

    Print preferred_size to see our change.

  4. Maria is having a hard time visualizing which customer is associated with each size. Let’s restructure our two lists into a two-dimensional list to help Maria.

    In addition to our already available data, Maria is adding a third value for each customer that reflects if they want expedited shipping on their orders.

    This will be reflected using a boolean value (True for expedited, False for regular)

    Create a two-dimensional list called customer_data using the following table as a reference for the data. Each sublist should contain a name, size, and expedited shipping option for a single person.

    Name Size Expedited Shipping
    "Ainsley" "Small" True
    "Ben" "Large" False
    "Chani" "Medium" True
    "Depak" "Medium" False

    Print customer_data to see the data.

  5. "Chani" reached out to Maria. She requested to switch to regular shipping to save some money.

    Change the data value for "Chani"‘s shipping preference to False in our two-dimensional list to reflect the change.

  6. "Ben" reached out to Maria asking to remove his shipping option (the True or False value) because he is unsure what type he wants.

    Use the .remove() method to delete the shipping value from the sublist that contains Ben’s data.

    Note: We never explicitly went over how to use the .remove() method on a 2d list together.

  7. Great job making it this far! One last thing, Maria received new customers, "Amit" and "Karim", the following 2d list contains their data:

    [["Amit", "Large", True], ["Karim", "X-Large", False]]

    Create a new variable customer_data_final. Combine our existing list customer_data with our new customer 2d list using + by adding it to the end of customer_data.

    Print customer_data_final to see our final result.

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.