PNL Learn

Python Lists and Loops

Store collections and repeat work with for and while.

Move past single values and start working with collections. You will build lists, read and change them by index from either end, append, extend, insert and remove items, search them, and slice them with steps. You will loop with for, range and while, steer loops with break, continue, pass and a loop's else, and learn the traps that catch every beginner: off-by-one indexes and ranges, an accumulator in the wrong place, removing items while looping, append versus extend, two names for one list, and sort() returning None. Then you will copy and sort lists, work with grids and nested loops, write list comprehensions, and finish with a grade report, a running-balance ledger, a longest-run tracker and a restock report.

BeginnerPython7 lessons84 exercisesAbout 6.5 h
Create a free account

What you will learn

  • Lists
  • Indexing
  • Slicing
  • List methods
  • for loops
  • range
  • while loops
  • break, continue and loop else
  • Aliasing and copying
  • Sorting
  • Nested lists
  • List comprehensions
  • Accumulation

Lessons

  1. 1

    Lists: Creating and Indexing

    Build a list, read items by position from either end, and change them in place.

    12 exercises

  2. 2

    Growing and Shrinking a List

    Add and remove items, search a list, and cut out slices, including every other item and the list reversed.

    13 exercises

  3. 3

    For Loops

    Walk through a list, count with range, build results as you go, and change a list safely while you loop.

    13 exercises

  4. 4

    While Loops and Control Flow

    Repeat based on a condition, steer a loop with break, continue and pass, and use a loop's else for searches.

    13 exercises

  5. 5

    Aliasing, Copying and Sorting

    Tell two names for one list from two lists, make real copies, and sort in place or into a new list.

    11 exercises

  6. 6

    Nested Lists and Comprehensions

    Loop inside a loop, store a grid as a list of lists, avoid the shared-row trap, and build lists in one line with a comprehension.

    12 exercises

  7. 7

    Putting It Together

    Combine loops, conditions, built-ins, sorting and grids into real tools: a grade report, a running-balance ledger, a streak tracker and a restock report.

    10 exercises

How you practice

You practice in the browser and every exercise gives you feedback right away. This course uses these formats:

  • Code exercise: 30
  • Fix the bug: 15
  • Predict the output: 13
  • Fill in the blank: 9
  • Type the answer: 7
  • Multiple choice: 4
  • Spot the bug: 3
  • Reorder lines: 3

Aligned to

PCEP-30-02Python InstituteSource
  • Control Flow - Conditional Blocks and Loops
    • 2.2Perform different types of iterations
  • Data Collections - Tuples, Dictionaries, Lists, and Strings
    • 3.1Collect and process data using lists
CS2023ACM / IEEE-CS / AAAISource
  • Software Development Fundamentals
    • SDF-FundamentalsFundamental Programming Concepts and Practices
    • SDF-Data-StructuresFundamental Data Structures

Proto Node Labs is not affiliated with or endorsed by Python Institute and ACM / IEEE-CS / AAAI. Exam names are trademarks of their owners.