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!

Problem solved, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.