CSC 161 Lecture Notes - Lecture 16: Lookup Table, Eval

9 views2 pages

Document Summary

It turns out that strings are really a special kind of sequence, so these operations also apply to sequences! >>> grades = ["a", "b", "c", "d", "f"] Strings are always sequences of characters, but lists can be sequences of arbitrary values lists can have numbers, strings, or both! mylist = [1, "spam ", 4, "u"] We can use the idea of a list to make our previous month program even simpler: we change the lookup table for months to a list: months = ["jan", "feb", "mar", "apr", "may", To get the months out of the sequence, do this: monthabbrev = months[n-1] rather than this: monthabbrev = months[pos:pos+3] # a program to print the month name, given it"s number. # this version uses a list as a lookup table. def main(): # months is a list used as a lookup table months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov",

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

Related Questions