# Swap proc (list)

Source: https://ref.dm-lang.org/list/proc/Swap

### Format
> `list.Swap(Index1,Index2)`

### Returns
> Nothing.

### Args
- `Index1`: The index (1 to list.len) of one of the items to swap.
- `Index2`: The index of the other item.


Swap two items in a list. If the list has associated values, they will be preserved. This is most useful for user-defined sorting routines.

```dm /Swap/
var/item
var/list/L = list("orange" = 3, "green" = 2, "blue" = 5)
for(item in L) world << "[item] -> [L[item]]"
world << ""
L.Swap(1, 3)
for(item in L) world << "[item] -> [L[item]]"
```

## Result:

```dm /Swap/
orange -> 3
green -> 2
blue -> 5

blue -> 5
green -> 2
orange -> 3
```

> [!note]
> 
> This proc doesn't work with many special lists such as `contents` or `overlays`.

### See also
- [Cut proc (list)](https://ref.dm-lang.org/list/proc/Cut.md)
- [Copy proc (list)](https://ref.dm-lang.org/list/proc/Copy.md)
- [Insert proc (list)](https://ref.dm-lang.org/list/proc/Insert.md)
