code: def reservoir_sample(stream, num_items, item_parser=lambda x: x):
      
      kept = []
      for index, item in enumerate(stream):
          if index < num_items:
              kept.append(item_parser(item))
          else:
              r = random.randint(0, index)
              if r < num_items:
                  kept[r] = item_parser(item)
      return kept
docs: samples num_items from the stream keeping each with equal probability