- #1
late347
- 301
- 15
I was making a little bit of a thought experiment with a simple program and wanted to double check it with you guys.
The idea was to utilize basic functionalities of python, regarding lists. Then the goal is to find out and print the number of times that a certain element occurs inside a particular list.
I think the code seems to work.
Is there a more specified way to test out whether or not a certain element appears in a list, and count how manys times that element appears in the list?
The idea was to utilize basic functionalities of python, regarding lists. Then the goal is to find out and print the number of times that a certain element occurs inside a particular list.
I think the code seems to work.
Is there a more specified way to test out whether or not a certain element appears in a list, and count how manys times that element appears in the list?
Python:
lista = [1, 2, 66, 77, 66, 54, -9, "citrus", 66, "citrus"]
citrusNumberOf = 0
for x in lista:
if x == "citrus":
citrusNumberOf = citrusNumberOf + 1
print(citrusNumberOf)