top of page

Genetics Refresher

Lists & Loops Refresher

List Methods

Dictionaries

Checkpoint

Build Your Own Protein

Summary

Lists & Loops Refresher

For this next section, we'll make significant use of loops and lists. So let's recall some of the basics.

Lists

List.png

For Loops

ForLoop.png

For this next section, we'll make significant use of loops and lists. So let's recall some of the basics. Lists are objects that can store multiple items as shown below in the list: lesson8_chapters (Note: Lists can store text and integers / floats as well as more complex objects).

1 lesson8_chapters ['genetics refresher', 'lists & loops refresher', 'list methods', 'dictionaries', 'checkpoint', 'build your own protein', 'summary']

The lists that we are working with are reasonable sizes, but in practical application, lists can be several magnitudes larger, so we need quick ways of referencing locations in a list and determining the overall size. This is demonstrated below with two functions, the first one prints the fifth item in the lesson8_chapters list (remember that lists are zero-indexed) and the second prints the length of the list.

print(lesson8_chapters[0])

2

print(len(lesson8_chapters))

When we have large lists, it is often helpful to iterate through the list automatically. This is where For loops cmoe in. Using the below syntax, we create a new variable called lesson_name which will represent one of the items in the lesson8_chapters list. Then it will print out each name. 

​

Recall that is also possible to combine for loops with if statements. Scientists will often use if statements in for loops to search for a particular item within a large list.

for lesson_name in lesson8_chapters:

2    print('Lesson 8 contains the following', lesson_name)

Using the terminal below, create a list called lesson8_chapters and print how many items are in the list that are not "checkpoint" or "summary".

​

In this case, pretend that you do not know how many items are in the list.

bottom of page