Advertisement
GCK

GCK/ count occurences function

GCK
Sep 26th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. from random import randint
  2.  
  3. marks=[randint(0,10) for x in range(30) ]
  4. msg="Hello Hello words Hello, everybody is fine ?"
  5. shopping=["tomatoes", "bread", "chocolate", "caviar", "bread", "pizza", "bread"]
  6.  
  7. def count_occurences(occurence,list_of_stuff):
  8.     count=0
  9.     for item in list_of_stuff:
  10.         if item==occurence:
  11.             count+=1
  12.     print("{} appears {} times in the list".format(occurence,count))
  13.     return count
  14.    
  15.  
  16.  
  17. count_occurences(10,marks)
  18. count_occurences("H",msg)
  19. count_occurences("bread",shopping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement