Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import typing as tp
- def filter_list_by_list(a: tp.Sequence[int], b: tp.Sequence[int]) -> tp.Sequence[int]:
- """
- Filter first sorted lists by other sorted list
- :param a: first sorted list
- :param b: second sorted list
- :return: filtered sorted list
- """
- result_list = []
- if len(b) == 0:
- return a
- if len(a) == 0:
- return []
- index_first = 0
- index_second = 0
- while index_first < len(a) and index_second < len(b):
- if a[index_first] < b[index_second]:
- result_list.append(a[index_first])
- index_first += 1
- elif a[index_first] > b[index_second]:
- index_second += 1
- else:
- index_first += 1
- if index_first < len(a):
- result_list.extend(a[index_first:])
- return result_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement