Program excercise : Write a function that takes two lists of strings as input, and returns a single list of unique strings common to both lists.

def common_strings(str_list1, str_list2):
    return [str_value for str_value in str_list1 if str_value in str_list2]

Another way,

def get_common_strs(list1,list2):
    return list(set(list1).intersection(set(list2)))


Comments

Popular posts from this blog

How to Install minikube in local mac machine?

Program excercise : Write a function that, using the Star Wars API (swapi.co), takes a character name, and returns a list with the names of the films that character was in.