Python Common Operations on Lists

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

l.append(e)

adds the object e to the end of l

l.sort()

has the side effect of sorting the elements of l.

l.insert(i, e)

inserts the object e into l at index i

l.pop(i)

removes and returns the item at index i. Default value for i is -1.

del l[i]

removes element with index i. Raises IndexError if i is out of range.

range(stop)

returns a list of integers starting a 0 and increasing by 1 up to, but not including stop. Examples: range(6) returns [0, 1, 2, 3, 4, 5] range(0) returns [] range(3) returns [0, 1, 2]

range(start, stop, step)

returns a list starting at start and going up to but not including stop. Default value for step is 1. All inputs must be integers. Examples: range(1, 5) returns [1, 2, 3, 4] range(0, 10, 3) returns [0, 3, 6, 9] range(1, 0) returns []

l.index(e)

returns the index of the first occurrence of e in l


Set pelajaran terkait

Chapter 13: Emotional and Social Development in Middle Childhood

View Set

Chapter 5 individual life insurance contract, provisions, and options quiz

View Set

geometry transformation definitions

View Set

AP Psychology Modules 1-8 Vocabulary

View Set

chapter 7- Thinking and intelligence

View Set

LS 7C Midterm 1 Learning Objectives

View Set

Geologic Structures, Maps, and Block Diagrams - Parts 1 and 2

View Set