Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Count number of occurrences of strings in a list
- def count_string(list_element,item_list):
- count = 0
- for item in item_list:
- if list_element == item:
- count += 1
- return count
- fruit = ["apples", "bananas", "pears", "apples", "oranges", "pears", "apples", "pears", "lime", "oranges"]
- fruit_number = count_string("pears",fruit)
- print("There are {0} in the list".format(fruit_number))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement