Write a function called both()
that will receive two lists and return a new list containing only the values that appear in both lists. It does not matter what order the values are in.
Examples:
both( [1, 2, 3, 4, 5], [2, 4, 6, 8] )
returns the list [2, 4]
both( [1, 3, 5], [2, 4, 6] )
returns the empty list []
Also use the randlist()
function you wrote in a previous assignment to test your function:
both( randlist(), randlist() )
returns ???For +10 bonus points, only use one loop. Also make sure your code still works even if the lists are different lengths.
©2017 Graham Mitchell