src/pylib/builtins/list

Search:
Group by:
Source   Edit  

Python's list with its methods and sorted buitin

LIMIT: slice literal is not supported. ls[1:3] has to be rewritten as ls[1..2]

Procs

func `*`[T](n: Natural; ls: PyList[T]): PyList[T]
Source   Edit  
func `*=`[T](self: var PyList[T]; n: int)
Source   Edit  
func `+`[T](self: PyList[T]; x: openArray[T]): PyList[T]
Source   Edit  
func `+=`[T](self: var PyList[T]; ls: openArray[T])
Source   Edit  
func `+=`[T](self: var PyList[T]; ls: PyList[T])
Source   Edit  
func `==`[T](self: PyList[T]; o: openArray[T]): bool
Source   Edit  
func `==`[T](self: PyList[T]; o: PyList[T]): bool
Source   Edit  
func `==`[T](self: PyList[T]; o: seq[T]): bool
Source   Edit  
func `[]`[T](self: PyList[T]; idx: int): T
Source   Edit  
func `[]`[T](self: PyList[T]; s: BackwardsIndex): T
Source   Edit  
func `[]`[T](self: PyList[T]; s: HSlice): PyList[T]
Source   Edit  
func `[]`[T](self: PyList[T]; s: PySlice): PyList[T]
Source   Edit  
func `[]=`[T](self: var PyList[T]; idx: int; x: T)
Source   Edit  
func `[]=`[T](self: var PyList[T]; s: BackwardsIndex; x: T)
Source   Edit  
func `[]=`[T](self: var PyList[T]; s: HSlice; x: Iterable[T])
Source   Edit  
func `[]=`[T](self: var PyList[T]; s: HSlice; x: openArray[T])
Source   Edit  
func `[]=`[T](self: var PyList[T]; s: HSlice; x: PyList[T])
Source   Edit  
func `[]=`[T](self: var PyList[T]; s: PySlice;
              x: not Sequence[T] and Iterable[T])
Source   Edit  
func `[]=`[T](self: var PyList[T]; s: PySlice; x: Sequence[T])
Source   Edit  
func append[T](self: var PyList[T]; x: T)
Source   Edit  
func clear(self: var PyList)
Source   Edit  
func delitem(self: var PyList; idx: int)
Source   Edit  
func extend[T](self: var PyList[T]; ls: openArray[T])
Source   Edit  
func insert[T](self: var PyList[T]; idx: int; x: T)
Source   Edit  
func list[T](): PyList[T]

Example:

assert len(list[int]()) == 0
Source   Edit  
func list[T](a: openArray[T]): PyList[T]
Source   Edit  
proc list[T](iter: Iterable[T]): PyList[T]
Source   Edit  
func list[T](x: seq[T]): PyList[T]
Source   Edit  
func pop[T](self: var PyList[T]): T {.discardable.}
Source   Edit  
func pop[T](self: var PyList[T]; index: int): T {.discardable.}
index can be negative to index backwards. Source   Edit  
func repr(ls: PyList[char]): string {....raises: [], tags: [], forbids: [].}
Source   Edit  
func reverse(self: var PyList)
Source   Edit  
proc sort[T, K](self: var PyList[T]; key: proc (x: T): K; reverse = false)
list.sort(key, reverse=False) Source   Edit  
func sort[T](self: var PyList[T]; reverse = false)
list.sort(reverse=False) Source   Edit  
func sorted[T, K](x: not Sequence[T] and Iterable[T]; key: proc (x: T): K;
                  reverse = false): PyList[T]
Source   Edit  
func sorted[T, K](x: Sequence[T]; key: proc (x: T): K; reverse = false): PyList[
    T]
Source   Edit  
func sorted[T](self: PyList[T]; reverse = false): PyList[T]
sorted(list, reverse=False) Source   Edit  

Converters

converter nimArrayAsList[T; I](arr: array[I, T]): PyList[T]
Source   Edit  

Templates

template `$`[T](ls: PyList[T]): string

The same as repr for PyList

NOTE: CPython's list's __str__ is itself not defined, which is inherted from object, which will call obj.__repr__ as fallback. This minics it.

Source   Edit  
template `*`[T](ls: PyList[T]; n: Natural): PyList[T]
Source   Edit  
template `+`[T](self: var PyList[T]; x: PyList[T]): PyList[T]
Source   Edit  
template `==`[T](o: openArray[T]; self: PyList[T]): bool
Source   Edit  
template `==`[T](o: seq[T]; self: PyList[T]): bool
Source   Edit  
template extend[T](self: var PyList[T]; ls: Iterable[T])
Source   Edit  
template len(self: PyList): int
Source   Edit  
template repr[T](ls: PyList[T]): string
mixin func repr(T): string Source   Edit