리스트 객체

PyListObject

PyObject의 서브 형은 파이썬 리스트 객체를 나타냅니다.

PyTypeObject PyList_Type

PyTypeObject 인스턴스는 파이썬 리스트 형을 나타냅니다. 이것은 파이썬 계층의 list와 같은 객체입니다.

int PyList_Check(PyObject *p)

p가 리스트 객체나 리스트 형의 서브 형 인스턴스면 참을 반환합니다.

int PyList_CheckExact(PyObject *p)

p가 리스트 객체이지만 리스트 형의 서브 형의 인스턴스가 아니면 참을 반환합니다.

PyObject* PyList_New(Py_ssize_t len)
Return value: New reference.

Return a new list of length len on success, or NULL on failure.

참고

len이 0보다 크면, 반환된 리스트 객체의 항목은 NULL로 설정됩니다. 따라서 모든 항목을 PyList_SetItem()로 실제 객체로 설정하기 전에 PySequence_SetItem()와 같은 추상 API 함수를 사용하거나 파이썬 코드에 객체를 노출할 수 없습니다.

Py_ssize_t PyList_Size(PyObject *list)

list에서 리스트 객체의 길이를 반환합니다; 이는 리스트 객체에 대한 len(list)와 동등합니다.

Py_ssize_t PyList_GET_SIZE(PyObject *list)

에러 검사 없는 PyList_Size()의 매크로 형식.

PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
Return value: Borrowed reference.

Return the object at position index in the list pointed to by list. The position must be non-negative; indexing from the end of the list is not supported. If index is out of bounds (<0 or >=len(list)), return NULL and set an IndexError exception.

PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
Return value: Borrowed reference.

에러 검사 없는 PyList_GetItem()의 매크로 형식.

int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item)

Set the item at index index in list to item. Return 0 on success. If index is out of bounds, return -1 and set an IndexError exception.

참고

이 함수는 item에 대한 참조를 “훔치고” 영향을 받는 위치의 리스트에 이미 있는 항목에 대한 참조를 버립니다.

void PyList_SET_ITEM(PyObject *list, Py_ssize_t i, PyObject *o)

에러 검사 없는 PyList_SetItem()의 매크로 형식. 일반적으로 이전 내용이 없는 새 리스트를 채우는 데 사용됩니다.

참고

이 매크로는 item에 대한 참조를 “훔치고”, PyList_SetItem()과는 달리 대체되는 항목에 대한 참조를 버리지 않습니다; listi 위치에 있는 참조는 누수를 일으킵니다.

int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item)

항목 item을 리스트 list의 인덱스 index 앞에 삽입합니다. 성공하면 0을 반환합니다; 실패하면 -1을 반환하고 예외를 설정합니다. list.insert(index, item)에 해당합니다.

int PyList_Append(PyObject *list, PyObject *item)

리스트 list의 끝에 객체 item을 추가합니다. 성공하면 0을 반환합니다; 실패하면 -1을 반환하고 예외를 설정합니다. list.append(item)에 해당합니다.

PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high)
Return value: New reference.

Return a list of the objects in list containing the objects between low and high. Return NULL and set an exception if unsuccessful. Analogous to list[low:high]. Indexing from the end of the list is not supported.

int PyList_SetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high, PyObject *itemlist)

Set the slice of list between low and high to the contents of itemlist. Analogous to list[low:high] = itemlist. The itemlist may be NULL, indicating the assignment of an empty list (slice deletion). Return 0 on success, -1 on failure. Indexing from the end of the list is not supported.

int PyList_Sort(PyObject *list)

list 항목을 제자리에서 정렬합니다. 성공하면 0을, 실패하면 -1을 반환합니다. 이것은 list.sort()와 동등합니다.

int PyList_Reverse(PyObject *list)

list의 항목을 제자리에서 뒤집습니다. 성공하면 0을, 실패하면 -1을 반환합니다. 이것은 list.reverse()와 동등합니다.

PyObject* PyList_AsTuple(PyObject *list)
Return value: New reference.

list의 내용을 포함하는 새 튜플 객체를 반환합니다; tuple(list)와 동등합니다.

int PyList_ClearFreeList()

자유 목록(free list)을 비웁니다. 해제된 항목의 총수를 반환합니다.

버전 3.3에 추가.