Copy the list to a new list.

        WARNING: If key exists, it clears it before copying.
433080
def copy(self, key):
        
        copy = List(key, self.db)
        copy.clear()
        copy.extend(self)
        return copy
218444
function addKeyToList(list, key, object) {
    for (var i = list.length - 1; i >= 0; i--) {
        if (list[i][key] == object[key]) {
            return false;
        }
    }
    list.push(object);
    return true;
}
478125
def copy(self, keep_fields=None):
        
        keep_fields = self.fields.keys() or keep_fields
        return self.__class__(OrderedDict([(name, data[:]) for name, data in self.fields.items() if name in keep_fields]))
1007108
def set(cls, obj, keys, value, fill_list_value=None):
        
        current = obj
        keys_list = keys.split(".")

        for idx, key in enumerate(keys_list, 1):
            if type(current) == list:
                # Validate this key works with a list.
                try:
                    key = int(key)
                except ValueError:
                    raise cls.Missing(key)

            try:
                # This is the last key, so set the value.
                if idx == len(keys_list):
                    if type(current) == list:
                        safe_list_set(
                            current,
                            key,
                            lambda: copy.copy(fill_list_value),
                            value
                        )
                    else:
                        current[key] = value

                    # done.
                    return

                # More keys left, ensure we have a container for this key.
                if type(key) == int:
                    try:
                        current[key]
                    except IndexError:
                        # Create a list for this key.
                        cnext = container_for_key(keys_list[idx])
                        if type(cnext) == list:
                            def fill_with():
                                return []
                        else:
                            def fill_with():
                                return {}

                        safe_list_set(
                            current,
                            key,
                            fill_with,
                            [] if type(cnext) == list else {}
                        )
                else:
                    if key not in current:
                        # Create a list for this key.
                        current[key] = container_for_key(keys_list[idx])

                # Move on to the next key.
                current = current[key]
            except (IndexError, KeyError, TypeError):
                raise cls.Missing(key)
724345
public static <T, K> boolean moveUp(List<T> list, K key,
			Function<T, K> keyMapper, int n) {
		if (list == null)
			return false;
		ArrayList<T> newList = new ArrayList<T>();
		boolean changed = false;
		for (int i = 0; i < list.size(); i++) {
			T item = list.get(i);

			if (i > 0 && key.equals(keyMapper.apply(item))) {
				int posi = i - n;
				if (posi < 0)
					posi = 0;
				newList.add(posi, item);
				changed = true;
			} else
				newList.add(item);
		}

		if (changed) {
			list.clear();
			list.addAll(newList);
			return true;
		}
		return false;
	}
985232
def copy(self):
        """"""
        args = []
        for arg in self.args:
            if isinstance(arg, Block):
                arg = arg.copy()
            elif isinstance(arg, list):
                arg = [b.copy() for b in arg]
            args.append(arg)
        return Block(self.type, *args)
86732
private List<SnakGroup> copy(List<SnakGroup> snakGroups) {
		List<SnakGroup> result = new ArrayList<>(snakGroups.size());
		for (SnakGroup snakGroup : snakGroups) {
			result.add(copy(snakGroup));
		}
		return result;
	}
1200461
def clear_instances(self, instances=None):
        
        if instances is None:
            instances = self.instances[:]  # have to make a copy of the list
        for instance in instances:
            self.remove_instance(instance)
648893
private List<Reference> copyReferences(List<Reference> references) {
		if (!deepCopyReferences) {
			return Collections.emptyList();
		}

		List<Reference> result = new ArrayList<>(references.size());
		for (Reference reference : references) {
			result.add(dataObjectFactory
					.getReference(copy(reference.getSnakGroups())));
		}
		return result;
	}
967911
def object_merge(old, new, unique=False):
    
    if isinstance(old, list) and isinstance(new, list):
        if old == new:
            return
        for item in old[::-1]:
            if unique and item in new:
                continue
            new.insert(0, item)
    if isinstance(old, dict) and isinstance(new, dict):
        for key, value in old.items():
            if key not in new:
                new[key] = value
            else:
                object_merge(value, new[key])
12217
def AppendUnique(self, delete_existing=0, **kw):
        
        kw = copy_non_reserved_keywords(kw)
        for key, val in kw.items():
            if SCons.Util.is_List(val):
                val = _delete_duplicates(val, delete_existing)
            if key not in self._dict or self._dict[key] in ('', None):
                self._dict[key] = val
            elif SCons.Util.is_Dict(self._dict[key]) and \
                 SCons.Util.is_Dict(val):
                self._dict[key].update(val)
            elif SCons.Util.is_List(val):
                dk = self._dict[key]
                if key == 'CPPDEFINES':
                    tmp = []
                    for i in val:
                        if SCons.Util.is_List(i):
                            if len(i) >= 2:
                                tmp.append((i[0], i[1]))
                            else:
                                tmp.append((i[0],))
                        elif SCons.Util.is_Tuple(i):
                            tmp.append(i)
                        else:
                            tmp.append((i,))
                    val = tmp
                    # Construct a list of (key, value) tuples.
                    if SCons.Util.is_Dict(dk):
                        tmp = []
                        for (k, v) in dk.items():
                            if v is not None:
                                tmp.append((k, v))
                            else:
                                tmp.append((k,))
                        dk = tmp
                    elif SCons.Util.is_String(dk):
                        dk = [(dk,)]
                    else:
                        tmp = []
                        for i in dk:
                            if SCons.Util.is_List(i):
                                if len(i) >= 2:
                                    tmp.append((i[0], i[1]))
                                else:
                                    tmp.append((i[0],))
                            elif SCons.Util.is_Tuple(i):
                                tmp.append(i)
                            else:
                                tmp.append((i,))
                        dk = tmp
                else:
                    if not SCons.Util.is_List(dk):
                        dk = [dk]
                if delete_existing:
                    dk = [x for x in dk if x not in val]
                else:
                    val = [x for x in val if x not in dk]
                self._dict[key] = dk + val
            else:
                dk = self._dict[key]
                if SCons.Util.is_List(dk):
                    if key == 'CPPDEFINES':
                        tmp = []
                        for i in dk:
                            if SCons.Util.is_List(i):
                                if len(i) >= 2:
                                    tmp.append((i[0], i[1]))
                                else:
                                    tmp.append((i[0],))
                            elif SCons.Util.is_Tuple(i):
                                tmp.append(i)
                            else:
                                tmp.append((i,))
                        dk = tmp
                        # Construct a list of (key, value) tuples.
                        if SCons.Util.is_Dict(val):
                            tmp = []
                            for (k, v) in val.items():
                                if v is not None:
                                    tmp.append((k, v))
                                else:
                                    tmp.append((k,))
                            val = tmp
                        elif SCons.Util.is_String(val):
                            val = [(val,)]
                        if delete_existing:
                            dk = list(filter(lambda x, val=val: x not in val, dk))
                            self._dict[key] = dk + val
                        else:
                            dk = [x for x in dk if x not in val]
                            self._dict[key] = dk + val
                    else:
                        # By elimination, val is not a list.  Since dk is a
                        # list, wrap val in a list first.
                        if delete_existing:
                            dk = list(filter(lambda x, val=val: x not in val, dk))
                            self._dict[key] = dk + [val]
                        else:
                            if not val in dk:
                                self._dict[key] = dk + [val]
                else:
                    if key == 'CPPDEFINES':
                        if SCons.Util.is_String(dk):
                            dk = [dk]
                        elif SCons.Util.is_Dict(dk):
                            tmp = []
                            for (k, v) in dk.items():
                                if v is not None:
                                    tmp.append((k, v))
                                else:
                                    tmp.append((k,))
                            dk = tmp
                        if SCons.Util.is_String(val):
                            if val in dk:
                                val = []
                            else:
                                val = [val]
                        elif SCons.Util.is_Dict(val):
                            tmp = []
                            for i,j in val.items():
                                if j is not None:
                                    tmp.append((i,j))
                                else:
                                    tmp.append(i)
                            val = tmp
                    if delete_existing:
                        dk = [x for x in dk if x not in val]
                    self._dict[key] = dk + val
        self.scanner_map_delete(kw)
270764
def _list_merge(src, dest):
    
    for k in src:
        if type(src[k]) != dict:
            dest[k] = src[k]
        else:
            # ---
            # src could have a key whose value is a list
            # and does not yet exist on dest
            if k not in dest:
                dest[k] = {}
            _list_merge(src[k], dest[k])
787484
public static <T, K> boolean move(List<T> list, K key,
			Function<T, K> keyMapper, int n) {
		if (n == 0)
			return false;

		if (n > 0)
			return moveDown(list, key, keyMapper, n);

		return moveUp(list, key, keyMapper, -n);
	}
311594
def copy( self ):
        
        ret = ParseResults( self.__toklist )
        ret.__tokdict = self.__tokdict.copy()
        ret.__parent = self.__parent
        ret.__accumNames.update( self.__accumNames )
        ret.__name = self.__name
        return ret
993207
public void copy() {
		StringBuffer sb = new StringBuffer();

		sb.append("Text 1 = ");
		if (tf1.getText() != null) {
			sb.append(tf1.getText());
		}
		sb.append("\nText 2 = ");
		if (tf2.getText() != null) {
			sb.append(tf2.getText());
		}
		sb.append("\nText 3 = ");
		if (tf3.getText() != null) {
			sb.append(tf3.getText());
		}
		sb.append("\nText 4 = ");
		if (tf4.getText() != null) {
			sb.append(tf4.getText());
		}

		sb.append("\nNumeric 1 = ");
		if (nf1.getText() != null) {
			sb.append(nf1.getText());
		}
		sb.append("\nNumeric 2 = ");
		if (nf2.getText() != null) {
			sb.append(nf2.getText());
		}
		sb.append("\nNumeric 3 = ");
		if (nf3.getText() != null) {
			sb.append(nf3.getText());
		}

		sb.append("\nEmail = ");
		if (ef1.getText() != null) {
			sb.append(ef1.getText());
		}

		if (drop1.getSelected() != null) {
			sb.append("\nDrop 1 = ").append(drop1.getSelected());
		}

		if (drop2.getSelected() != null) {
			sb.append("\nDrop 2 = ").append(drop2.getSelected());
		}

		sb.append("\nMulti1 = ");
		List selected = multi1.getSelected();

		if (selected != null) {
			for (int i = 0; i < selected.size(); i++) {
				if (i > 0) {
					sb.append(", ");
				}

				sb.append(selected.get(i).toString());
			}
		}

		sb.append("\nMulti2 = ");
		selected = multi2.getSelected();

		if (selected != null) {
			for (int i = 0; i < selected.size(); i++) {
				if (i > 0) {
					sb.append(", ");
				}

				TableEntry entry = (TableEntry) selected.get(i);
				sb.append(entry.getCode());
			}
		}

		sb.append("\nMultiCb = ");
		List selectedOptions = multiCb.getSelected();

		for (int i = 0; i < selectedOptions.size(); i++) {
			if (i > 0) {
				sb.append(", ");
			}

			TableEntry entry = (TableEntry) selectedOptions.get(i);
			sb.append(entry.getCode());
		}

		if (rbSelect.getSelected() != null) {
			String radioValue = rbSelect.getSelected().toString();
			sb.append("\nWRadioButtonSelect = ").append(radioValue);
		}

		if (radioButtonGroup.getSelectedValue() != null) {
			String radioValue = radioButtonGroup.getSelectedValue();
			sb.append("\nRadioButtonGroup = ").append(radioValue);
		}

		sb.append("\nCheckboxes =");

		if (cb1.isSelected()) {
			sb.append(' ').append(cb1.getLabel().getText());
		}

		if (cb2.isSelected()) {
			sb.append(' ').append(cb2.getLabel().getText());
		}

		if (cb3.isSelected()) {
			sb.append(' ').append(cb3.getLabel().getText());
		}

		sb.append('\n');

		ta.setText(sb.toString());
	}
806862
def _list_to_set(self, list_key, set_key):
        
        if self.cls.database.support_scripting():
            self.cls.database.call_script(
                # be sure to use the script dict at the class level
                # to avoid registering it many times
                script_dict=self.__class__.scripts['list_to_set'],
                keys=[list_key, set_key]
            )
        else:
            conn = self.cls.get_connection()
            conn.sadd(set_key, *conn.lrange(list_key, 0, -1))
1056068
def copy(self, key=None):
        
        other = self.__class__(
            maxsize=self.maxsize, redis=self.persistence.redis, key=key
        )
        other.update(self)

        return other