0

Hey, I'm new to the language and was hoping someone could give me a bit of a hand.

[language=code]def common_elements(list1, list2):
"""
Return a list containing the elements which are in both list1 and list2

>>> common_elements([1,2,3,4,5,6], [3,5,7,9])
[3, 5]
>>> common_elements(,)

"""
list3 = []
for item in list1:
if item in list2:
list3.append(item)
print list3[/language]

At the moment this code wont pass the doctest I added in, because it prints 'this' twice. Normally I wouldn't add the doctest, but I'm hoping it will help people see what's wrong.

Thanks!

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by CommanderOne
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.