Write a Python program to find the difference between two list including duplicate elements

  • برمجة
  • برمجة بايثون

 Write a Python program to find the difference between two list including duplicate elements.

الأجوبة

def list_difference(l1,l2):
    result = list(l1)
    for el in l2:
        result.remove(el)
    return result
l1 = [1,1,2,3,3,4,4,5,6,7]
l2 = [1,1,2,4,5,6]

print("Original lists:")
print(l1)
print(l2)
print("\nDifference between two said list including duplicate elements):")
print(list_difference(l1,l2))
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...