Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • LED Lights

LED Lights

Zip Lists Together


Did You Know: zip() Function

Sometimes, a Python script needs a loop to access each successive item in more than one list.  For example, maybe each color has a corresponding on-time in a different list.  When used in place of in range(), Python’s zip() function makes this easy.  Here’s an example:

# lists_with_zip

from microbit import *

color_list  = ['green', 'yellow', 'red']
time_list   = [ 1000,    200,      500]

for color, time in zip(color_list, time_list):
    print('color:', color, '| time:', time)

print('Done!')

The first time through the loop, the color variable stores ’green’, while the time variable stores 1000.  The second time through, color is ’yellow’,  and time is 200.  The third time through, color is ’red’ and time is 500.  Each time through the loop,  print(’color:’, color, ’| time:’, time) displays both variables.
 


Your Turn: Add a Times List

Now that you’ve seen how to use a single loop with the zip() function to access related items in more than one list, let’s try it with custom LED on-times.

  • Click Open and reopen led_blink_list.hex.
  • Set the project name field and line-1 comment to led_blink_list_your_turn.
  • Modify the script as shown below, then click Save.
  • Click Send to micro:bit.
  • Check to make sure that the green light stays on for about a second, the yellow light stays on for about 1/5th of a second, and the red light stays on for about half a second.

 


Printer-friendly version
How it Works
Prev
Review and Practice
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress