Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Create a function called filter_interesting(a_list) that, given a list of wor

ID: 3780344 • Letter: 3

Question

3. Create a function called filter_interesting(a_list) that, given a list of words, returns a list containing only those words from the list a_list that are found to be interesting according to the criteria of exercise #2 above. The function header should be as follows: def filter_interesting(a_list)

For example, given the following list a_list_of_words = [“hulk”,“spiderman”,“batman”,“superman”,”thor”,”ironman”,“captainamerica”, “ultron”, “falcon”], the call filter_interesting(a_list_of_words) returns the list [‘spiderman’, 'batman', 'superman', ‘ironman', ‘captainamerica', ‘ultron’, ‘falcon’]

Explanation / Answer

def is_interesting(a_string):
count = 0
for i in range(0, len(a_string)):
ch = a_string[i]
if ch == 'a' or ch =='i' or ch == 'e' or ch == 'o' or ch == 'u':
count = count + 1
if isPrime(count):
return True;
else:
return False;
  
def isPrime(n):
if n < 2:
return False;
for i in range(2, n/2):
if n % i == 0:
return False;
return True;
     
  
  
def filter_interesting(a_list):
list = []
for i in range(0,len(a_list)):
if is_interesting(a_list[i]):
list.append(a_list[i])
return list;
  
a_list_of_words = ["hulk","spiderman","batman","superman","thor","ironman","captainamerica", "ultron", "falcon"]
print filter_interesting(a_list_of_words);

Output:

sh-4.3$ python main.py                                                                                                                                                                                                                                 

['spiderman', 'batman', 'superman', 'ironman', 'captainamerica', 'ultron', 'falcon']

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote