You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The second line here - the line with ages is a list comprehension.
163
+
164
+
It accomplishes the same thing as the first code sample - at the end,
165
+
the ages variable has a list containing [24, 23, 24, 24, 22, 23],
166
+
the ages corresponding to all the birthdates.
167
+
168
+
The idea of the list comprehension is to condense the for loop and the list appending into one simple line. Notice that the for loop just shifted to the end of the list comprehension, and the part before the for keyword is the thing to append to the end of the new list.
169
+
170
+
Happy coding! :)
171
+
172
+
173
+
### Question 6
174
+
#### List Overlap
175
+
176
+
Take two lists, say for example these two:
177
+
```python
178
+
179
+
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
180
+
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
181
+
182
+
```
183
+
184
+
And write a program that returns a list that contains only the elements that are common between the lists (without duplicates).
185
+
Make sure your program works on two lists of different sizes.
186
+
187
+
Bonus:
188
+
189
+
Randomly generate two lists to test this
190
+
Write this in one line of Python
191
+
192
+
List properties (In other words, “things you can do with lists.”)
193
+
194
+
One of the interesting things you can do with lists in Python is figure out whether something is inside the list or not. For example:
195
+
196
+
```python
197
+
198
+
>>> a = [5, 10, 15, 20]
199
+
>>>10in a
200
+
True
201
+
>>>3in a
202
+
False
203
+
204
+
```
205
+
206
+
You can of course use this in loops, conditionals, and any other programming constructs.
0 commit comments