Tip:
Highlight text to annotate it
X
[Andy] Now, what if our data structure was a bit more complicated
than a list with strings as entries?
Here we have a list where each entry is a tuple, as indicated by these parentheses.
For now let's just think of tuples as unchangeable or immutable lists.
Each of these tuples contains a TA name, the country where that TA lives,
and the course which that TA is currently instructing.
This data is interesting, but I'd rather have it presented to me as a list of sentences,
and we can do that with list comprehensions.
So here we've turned ta_data into a list of strings,
and each of those strings is a sentence about a TA.
For example, Peter lives in USA and is the TA for CS262.
How do we do that?
We use the same sort of list comprehension we used last time,
but now ta_data is an iterable and its entries are tuples.
These tuples each have 3 entries, and when we reference these names here, here, and here,
Python understands what we're talking about.
Now let's have a quiz.
Using the same structure for ta_data that we had before,
I want to construct sentences but only about the country in which each TA lives.
For example, Peter lives in USA,
or Gundega lives in Latvia.
I've given you 3 options for possible list comprehensions
that may accomplish this task--
that given ta_data will produce the correct ta_country.
And so which of the following list comprehensions will work?
Check all that apply.