python - creating a list filled with alike values of two different lists -
the whole point of me doing learn how code python without using built in functions given, such sort(), max(), , min(). need create function takes 2 lists arguments , creates new list filled alike values of 2 lists being passed function. new_list cannot take duplicates if list1= [1,2,2,3,4] , list2 = [1,2,2,3,4] new_list should = [1,2,3,4]. problem function have use python built in function in check if x not in new_list. how can extend function check if value within new_list without using python's built-in functions?
def alike_values(list1, list2): new_list = [] in list1: x in list2: if == x , x not in new_list: new_list.append(i) return new_list
you create second function, checks if value contained in list:
def alike_values(list1, list2): new_list = [] in list1: x in list2: if == x , not in_list(new_list, x): new_list.append(i) return new_list def in_list(li, val): in li: if == val: return true return false
Comments
Post a Comment