Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- def filter_forbidden_numbers(data, suspects):
- #to program to work run this function with data sets as in specification:
- #data = A, suspects = B
- #million iterations of provided data run in 17.801 seconds
- #so one iteration took around 17,8 microseconds
- items_counted = Counter(suspects)
- primes = get_prime_numbers_up_to(max(Counter(suspects).values()))
- forbidden_numbers = get_list_of_keys_that_values_appear_in_list(items_counted, primes)
- authorized_data = []
- for number in data:
- if number not in forbidden_numbers:
- authorized_data += [number]
- return authorized_data
- def get_list_of_keys_that_values_appear_in_list(dictionary, filtering_list):
- appeared_in_list = []
- for key in dictionary:
- if dictionary[key] in filtering_list:
- appeared_in_list += [key]
- return appeared_in_list
- def get_prime_numbers_up_to(number):
- prime_list = []
- for i in range(2, number + 1):
- if is_prime(i):
- prime_list += [i]
- return prime_list
- def is_prime(number):
- if number >= 2:
- for divisor in range(2, number):
- if not number % divisor:
- return False
- else:
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement