Deduplicate an item list, and preserve order.

    For case-insensitive lists, drop items if they case-insensitively match
    a prior item.
183829
def _dedup(items, insensitive):
    '''
    
    '''
    deduped = []
    if insensitive:
        i_deduped = []
        for item in items:
            lowered = item.lower()
            if lowered not in i_deduped:
                deduped.append(item)
                i_deduped.append(lowered)
    else:
        for item in items:
            if item not in deduped:
                deduped.append(item)
    return deduped
382033
function deduplicate(array, areEqual) {
        var result;
        if (array) {
            result = [];
            loop: for (var _i = 0, array_6 = array; _i < array_6.length; _i++) {
                var item = array_6[_i];
                for (var _a = 0, result_1 = result; _a < result_1.length; _a++) {
                    var res = result_1[_a];
                    if (areEqual ? areEqual(res, item) : res === item) {
                        continue loop;
                    }
                }
                result.push(item);
            }
        }
        return result;
    }
300922
def _remove_duplicates(self, items):
        
        result = []
        for i in items:
            if i not in result:
                result.append(i)
        return result
371031
def delete_item(name)
      previous = items.size
      items.reject! { |item| item.name == name}
      previous != items.size
    end
784361
def items_differ(jsonitems, dbitems, subfield_dict):
    

    # short circuit common cases
    if len(jsonitems) == len(dbitems) == 0:
        # both are empty
        return False
    elif len(jsonitems) != len(dbitems):
        # if lengths differ, they're definitely different
        return True

    original_jsonitems = jsonitems
    jsonitems = copy.deepcopy(jsonitems)
    keys = jsonitems[0].keys()

    # go over dbitems looking for matches
    for dbitem in dbitems:
        order = getattr(dbitem, 'order', None)
        match = None
        for i, jsonitem in enumerate(jsonitems):
            # check if all keys (excluding subfields) match
            for k in keys:
                if k not in subfield_dict and getattr(dbitem, k) != jsonitem.get(k, None):
                    break
            else:
                # all fields match so far, possibly equal, just check subfields now
                for k in subfield_dict:
                    jsonsubitems = jsonitem[k]
                    dbsubitems = list(getattr(dbitem, k).all())
                    if items_differ(jsonsubitems, dbsubitems, subfield_dict[k][2]):
                        break
                else:
                    # if the dbitem sets 'order', then the order matters
                    if order is not None and int(order) != original_jsonitems.index(jsonitem):
                        break
                    # these items are equal, so let's mark it for removal
                    match = i
                    break

        if match is not None:
            # item exists in both, remove from jsonitems
            jsonitems.pop(match)
        else:
            # exists in db but not json
            return True

    # if we get here, jsonitems has to be empty because we asserted that the length was
    # the same and we found a match for each thing in dbitems, here's a safety check just in case
    if jsonitems:       # pragma: no cover
        return True

    return False
137808
def dedupe_list_of_dicts(ld):
    
    def _freeze(o):
        """Recursively freezes a dict into an hashable object.

        Adapted from http://stackoverflow.com/a/21614155/374865.
        """
        if isinstance(o, dict):
            return frozenset((k, _freeze(v)) for k, v in six.iteritems(o))
        elif isinstance(o, (list, tuple)):
            return tuple(_freeze(v) for v in o)
        else:
            return o

    result = []
    seen = set()

    for d in ld:
        f = _freeze(d)
        if f not in seen:
            result.append(d)
            seen.add(f)

    return result
234691
def reduce_lists(d):
    """"""
    for field in d:
        old_data = d[field]
        if len(old_data) == 1:
            d[field] = old_data[0]
181309
function replaceAt(items, item, index) {
  var copy = items.slice();
  copy.splice(index, 1, item);
  return copy;
}
564008
def _avoid_duplicate_arrays(types):
    
    arrays = [t for t in types if isinstance(t, dict) and t["type"] == "array"]
    others = [t for t in types if not (isinstance(t, dict) and t["type"] == "array")]
    if arrays:
        items = set([])
        for t in arrays:
            if isinstance(t["items"], (list, tuple)):
                items |= set(t["items"])
            else:
                items.add(t["items"])
        if len(items) == 1:
            items = items.pop()
        else:
            items = sorted(list(items))
        arrays = [{"type": "array", "items": items}]
    return others + arrays
1293593
def flatlist_dropdup(list_of_lists):
    
    return list(set([str(item) for sublist in list_of_lists for item in sublist]))
873706
def remove_dups(head):
    
    hashset = set()
    prev = Node()
    while head:
        if head.val in hashset:
            prev.next = head.next
        else:
            hashset.add(head.val)
            prev = head
        head = head.next
1304913
def duplicates(coll):
    
    return list(set(x for x in coll if coll.count(x) > 1))
64737
boolean checkDuplicates(List<List<NodeInfo>> grid ) {

		for (int i = 0; i < listInfo.size; i++) {
			listInfo.get(i).marked = false;
		}

		for (int i = 0; i < grid.size(); i++) {
			List<NodeInfo> list = grid.get(i);
			for (int j = 0; j < list.size(); j++) {
				NodeInfo n = list.get(j);
				if( n.marked )
					return true;
				n.marked = true;
			}
		}
		return false;
	}
1244931
def __remove_duplicates(self, _other):
        """"""
        if not isinstance(_other, type(self)) \
           and not isinstance(_other, type(list)) \
           and not isinstance(_other, type([])):
            other = [_other]
        else:
            other = list(_other)

        # remove items already in self
        newother = []
        for i in range(0, len(other)):
            item = other.pop(0)
            if not list.__contains__(self, item):
                newother.append(item)

        # remove duplicate items in other
        other = []
        if newother != []:
            other.append(newother[0])
            for i in range(1, len(newother)):
                item = newother.pop()
                if not other.__contains__(item):
                    other.append(item)
        return other
825476
private void minimize() {

        // Algorithm: compare each entry n to all subsequent entries in
        // the list: if any subsequent entry matches or widens entry n,
        // remove entry n. If any subsequent entries narrow entry n, remove
        // the subsequent entries.
        for (int i = 0; i < size(); i++) {
            GeneralNameInterface current = getGeneralNameInterface(i);
            boolean remove1 = false;

            /* compare current to subsequent elements */
            for (int j = i + 1; j < size(); j++) {
                GeneralNameInterface subsequent = getGeneralNameInterface(j);
                switch (current.constrains(subsequent)) {
                    case GeneralNameInterface.NAME_DIFF_TYPE:
                        /* not comparable; different name types; keep checking */
                        continue;
                    case GeneralNameInterface.NAME_MATCH:
                        /* delete one of the duplicates */
                        remove1 = true;
                        break;
                    case GeneralNameInterface.NAME_NARROWS:
                        /* subsequent narrows current */
                        /* remove narrower name (subsequent) */
                        remove(j);
                        j--; /* continue check with new subsequent */
                        continue;
                    case GeneralNameInterface.NAME_WIDENS:
                        /* subsequent widens current */
                        /* remove narrower name current */
                        remove1 = true;
                        break;
                    case GeneralNameInterface.NAME_SAME_TYPE:
                        /* keep both for now; keep checking */
                        continue;
                }
                break;
            } /* end of this pass of subsequent elements */

            if (remove1) {
                remove(i);
                i--; /* check the new i value */
            }

        }
    }
358564
def duplicates_removed(it, already_seen=()):
    
    lst = []
    seen = set()
    for i in it:
        if i in seen or i in already_seen:
            continue
        lst.append(i)
        seen.add(i)
    return lst
990884
def purge_duplicates(list_in):
    
    _list = []
    for item in list_in:
        if item not in _list:
            _list.append(item)
    return _list