INFO1110 Lecture Notes - Lecture 4: Order Of Merit

11 views1 pages

Document Summary

Use len to nd the length of a list. print(len(my_list)) A list can be indexed using square brackets []. Note: the rst element in the list is at index zero. list elements 5 3 8 6 index. What happens when we choose an index that doesn"t exist? print(my_list[4]) Recall, we can use a while loop to count. Why not count the indices of the list from. 0 up to one less than the length of the list. i = 0 while i < len(my_list): print(i) i = i + 1. Rather than printing out the index, let"s use it to index the list and print out the element at that index. i = 0 while i < len(my_list): elem = my_list[i] print(elem)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents