Did I find the right examples for you? yes no

All Samples(11)  |  Call(11)  |  Derive(0)  |  Import(0)
Merges an arbitrary number of pre-sorted lists in-place, into the first
list, possibly pruning out duplicates. Source lists must not have
duplicates.

Args:
  list1: The first, sorted list into which the other lists should be merged.
  list2: A subsequent, sorted list to merge into the first.
  ...
  listn:  "   "
  cmp_fn: An optional binary comparison function that compares objects across(more...)

        def merge_in_place(*lists, **kwargs):
  """Merges an arbitrary number of pre-sorted lists in-place, into the first
  list, possibly pruning out duplicates. Source lists must not have
  duplicates.

  Args:
    list1: The first, sorted list into which the other lists should be merged.
    list2: A subsequent, sorted list to merge into the first.
    ...
    listn:  "   "
    cmp_fn: An optional binary comparison function that compares objects across
        lists and determines the merged list's sort order.
    dup_fn: An optional binary comparison function that should return True if
        the given objects are equivalent and one of them can be pruned from the
        resulting merged list.

  Returns:
    list1, in-placed merged wit the other lists, or an empty list if no lists
    were specified.
  """
  cmp_fn = kwargs.get('cmp_fn') or cmp
  dup_fn = kwargs.get('dup_fn') or None

  if not lists:
    return []

  reverse_indices = [len(arr) for arr in lists]
  aggregate_reverse_index = sum(reverse_indices)

  while aggregate_reverse_index > 0:
    pull_arr_index = None
    pull_val = None

    for i in range(len(lists)):
      if reverse_indices[i] == 0:
        # Reached the end of this list.
        pass
      elif (pull_arr_index is not None and
            dup_fn and dup_fn(lists[i][-reverse_indices[i]], pull_val)):
        # Found a duplicate, advance the index of the list in which the
        # duplicate was found.
        reverse_indices[i] -= 1
        aggregate_reverse_index -= 1
      elif (pull_arr_index is None or
            cmp_fn(lists[i][-reverse_indices[i]], pull_val) < 0):
        # Found a lower value.
        pull_arr_index = i
        pull_val = lists[i][-reverse_indices[i]]

    if pull_arr_index != 0:
      # Add the lowest found value in place into the first array.
      lists[0].insert(len(lists[0]) - reverse_indices[0], pull_val)

    aggregate_reverse_index -= 1
    reverse_indices[pull_arr_index] -= 1

  return lists[0]
        


src/g/e/GeoRemindMe_Web-HEAD/src/webapp/geomodel/geomodel.py   GeoRemindMe_Web(Download)
    def _merge_results_in_place(a, b):
      util.merge_in_place(a, b,
                        cmp_fn=lambda x, y: cmp(x[1], y[1]),
                        dup_fn=lambda x, y: x[0].key() == y[0].key())
 

src/s/t/stickup-HEAD/service/google-app-engine/geo/geomodel.py   stickup(Download)
 
        # Duplicates aren't possible so don't provide a dup_fn.
        util.merge_in_place(cmp_fn=_ordering_fn, *cell_results)
        results = cell_results[0][:max_results]
      else:
    def _merge_results_in_place(a, b):
      util.merge_in_place(a, b,
                        cmp_fn=lambda x, y: cmp(x[1], y[1]),
                        dup_fn=lambda x, y: x[0].key() == y[0].key())
 

src/g/e/geomodel-0.2.0/src/geo/geomodel.py   geomodel(Download)
 
        # Duplicates aren't possible so don't provide a dup_fn.
        util.merge_in_place(cmp_fn=_ordering_fn, *cell_results)
        results = cell_results[0][:max_results]
      else:
    def _merge_results_in_place(a, b):
      util.merge_in_place(a, b,
                        cmp_fn=lambda x, y: cmp(x[1], y[1]),
                        dup_fn=lambda x, y: x[0].key() == y[0].key())
 

src/c/i/City-Go-Round-HEAD/geo/geomodel.py   City-Go-Round(Download)
 
        # Duplicates aren't possible so don't provide a dup_fn.
        util.merge_in_place(cmp_fn=_ordering_fn, *cell_results)
        results = cell_results[0][:max_results]
      else:
    def _merge_results_in_place(a, b):
      util.merge_in_place(a, b,
                        cmp_fn=lambda x, y: cmp(x[1], y[1]),
                        dup_fn=lambda x, y: x[0].key() == y[0].key())
 

src/w/h/where-do-you-go-HEAD/geo/geomodel.py   where-do-you-go(Download)
 
        # Duplicates aren't possible so don't provide a dup_fn.
        util.merge_in_place(cmp_fn=_ordering_fn, *cell_results)
        results = cell_results[0][:max_results]
      else:
    def _merge_results_in_place(a, b):
      util.merge_in_place(a, b,
                        cmp_fn=lambda x, y: cmp(x[1], y[1]),
                        dup_fn=lambda x, y: x[0].key() == y[0].key())
 

src/g/e/GeoRemindMe_Web-HEAD/src/webapp/geomodel/util_test.py   GeoRemindMe_Web(Download)
    list6 = []
 
    util.merge_in_place(list1, list2, list3, list4, list5, list6,
        dup_fn=lambda x, y: x == y)
 

src/c/i/City-Go-Round-HEAD/geo/util_test.py   City-Go-Round(Download)
    list6 = []
 
    util.merge_in_place(list1, list2, list3, list4, list5, list6,
        dup_fn=lambda x, y: x == y)