Write a Python program to count the occurrence of each element of a given list.

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

Write a Python program to count the occurrence of each element of a given list.

الأجوبة

from collections import Counter
colors = ['Green', 'Red', 'Blue', 'Red', 'Orange', 'Black', 'Black', 'White', 'Orange']
print("Original List:")
print(colors)
print("Count the occurrence of each element of the said list:")
result = Counter(colors)
print(result)
nums = [3,5,0,3,9,5,8,0,3,8,5,8,3,5,8,1,0,2]
print("\nOriginal List:")
print(nums)
print("Count the occurrence of each element of the said list:")
result = Counter(nums)
print(result)
هل كان المحتوى مفيد؟

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

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