Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import typing as tp
  2.  
  3.  
  4. def filter_list_by_list(a: tp.Sequence[int], b: tp.Sequence[int]) -> tp.Sequence[int]:
  5.     """
  6.    Filter first sorted lists by other sorted list
  7.    :param a: first sorted list
  8.    :param b: second sorted list
  9.    :return: filtered sorted list
  10.    """
  11.     result_list = []
  12.     if len(b) == 0:
  13.         return a
  14.     if len(a) == 0:
  15.         return []
  16.     index_first = 0
  17.     index_second = 0
  18.     while index_first < len(a) and index_second < len(b):
  19.         if a[index_first] < b[index_second]:
  20.             result_list.append(a[index_first])
  21.             index_first += 1
  22.         elif a[index_first] > b[index_second]:
  23.             index_second += 1
  24.         else:
  25.             index_first += 1
  26.     if index_first < len(a):
  27.         result_list.extend(a[index_first:])
  28.     return result_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement