Exercise 5 (and Solution)
Take two lists, say for example these two:
and write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes.
- Randomly generate two lists to test this
- Write this in one line of Python (don’t worry if you can’t figure this out at this point - we’ll get to it soon)
In other words, “things you can do with lists.”
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:
You can of course use this in loops, conditionals, and any other programming constructs.
Forgot how to submit exercises?
comments powered by