python programming: chapter 7 Lists and tuples

Ace your homework & exams now with Quizwiz!

You can iterate over a list using a for loop such as...

...Format: for x in list:

To make a copy of a list you must copy each element of the list Two methods to do this:

Creating a new empty list and using a for loop to add a copy of each element from the original list to the new list Creating a new empty list and concatenating the old list to the new empty list

Format: list =

[item1, item2, etc.]

Two-dimensional list:

a list that contains other lists as its elements

Index:

a number specifying the position of an element in a list

Slice:

a span of items that are taken from a sequence

Tuple:

an immutable sequence

Similarly you can use the not in operator to determine whether

an item is not in a list

List:

an object that contains multiple data items

min and max functions:

built-in functions that returns the item that has the lowest or highest value in a sequence

print function

can be used to display an entire list

list() function

can convert certain types of objects to lists

The += augmented assignment operator can also be used to

concatenate lists

list() function:. tuple() function:

converts tuple to list converts list to tuple

You can use the in operator to

determine whether an item is contained in a list General format: item in list

IndexError exception

is raised if an invalid index is used

Concatenate:

join two things together The + operator can be used to concatenate two lists

Repetition operator:

makes multiple copies of a list and joins them together

del statement:

removes an element from a specific index in a list

len function

returns the length of a sequence such as a list

To process data in a two-dimensional list need to

to use two indexes

Format: tuple_name =

tuple_name = (item1, item2)

append(item):

used to add items to a list - item is appended to the end of the existing list

index(item):

used to determine where an item is located in a list


Related study sets

Driver's Ed | Chapter 8 | Options and Choices

View Set

Smartbook Recharge Chapter 14 ACCT 405

View Set

State Regulation and Principals Checkpoint Quiz

View Set

Web Development Chapter 6 Review

View Set

Biological Rhythms (EPM & EZ + Circadian Rhythms)

View Set