Python list operations

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

map(function, sequence)

calls function(item) for each of the sequence's items and returns a list of the return values.

filter(function, sequence)

returns a sequence consisting of those items from the sequence for which function(item) is true.

reduce(function, sequence)

returns a single value constructed by calling the binary function function on the first two items of the sequence, then on the result and the next item, and so on.

list.append(x)

Add an item to the end of the list; equivalent to a[len(a):] = [x].

list.extend(L)

Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.

list.insert(i, x)

Insert an item at a given position. The first argument is the index of the element before which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x).

'combinator'.join(list)

Joins all list items into a combinator-separated string.

'combinator'.join(list[indices])

Joins list items at 0-based specified indices into a combinator-separated string.

len(list)

Measures a list's length in words.

list.remove(x)

Remove the first item from the list whose value is x. It is an error if there is no such item.

list.pop([i])

Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list.

list.index(x)

Return the index in the list of the first item whose value is x. It is an error if there is no such item.

list.count(x)

Return the number of times x appears in the list.

list[index]

Returns the list item at 0-based specified index. [-1] returns the last item.

list.reverse()

Reverse the elements of the list, in place.

list.sort(cmp=None, key=None, reverse=False)

Sort the items of the list in place (the arguments can be used for sort customization, see sorted() for their explanation).

sum(sequence)

summing numbers


संबंधित स्टडी सेट्स

Similarity and Proportions Retake Guide

View Set

Unit 7_STATISTICAL QUALITY CONTROL

View Set

BIO 220 - Chapter 43 - HW and Quiz

View Set

Chapter 7: Portable fire extinguishers

View Set

Lewis Ch. 23 - Integumentary Problems, Lewis - Med-Surg Nursing - Study Guide - Ch. 11, alterations in skin integrity Questions

View Set

Module 13 Chapter 23 Quiz Natural Selection and Evolution

View Set

Business Law 1 - Chap 15: Third-Party Rights and Discharge

View Set