Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Counting occurrence in a lsit, whether numbers or strings
- import random
- # Add your count function here
- def count(target_grade,scores_list):
- target_hits = 0
- for score in scores_list:
- if score == target_grade:
- target_hits += 1
- return target_hits, target_grade
- # "Create" a list of scores, random integeres, then convert
- # it to a list of strings
- scores = []
- stringed_scores = []
- for x in range (0, 30):
- scores.append(random.randint(0, 10))
- stringed_scores.append(str(scores[x]))
- print("list of scores ", scores)
- print("list of stringed scores ", stringed_scores)
- print(count('5', stringed_scores))
- print("try another list of strings")
- mestring= ["me", "ego", "selfish", "pig", "pig", "me", "mine", "pig"]
- print(mestring)
- print(count("pig", mestring))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement