Comp Prog 1284: Exam 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/37

flashcard set

Earn XP

Description and Tags

Lists, Loops, and Functions

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

38 Terms

1
New cards

Container

an object that groups related objects together

2
New cards

Mutable

value can be changed after it has been created (EX. lists, dictionaries)

3
New cards

Immutable

value can not be changed after it has been created (EX. numbers, strings, tuples)

4
New cards

List

a mutable container, meaning the size of this can grow or shrink and elements within can change

5
New cards

Items in a list are called…

elements

6
New cards

Code for creating a list

list()

7
New cards

Another way to create a list (EX. put 1, 2, & 3 into my_list)

my_list = [1, 2, 3]

8
New cards

Index

a zero-based integer matching to a specific position in the list’s sequence of elements

9
New cards

Code for indexing in a list (EX. trying to find the 2nd item in my_list)

my_list[1]

10
New cards

A list’s index must be an _______ type

integer

11
New cards

In-place modifications

the ability to grow or shrink a list

12
New cards

Code for changing the value of element at index i in my_list

my_list[i] = x

13
New cards

Lists are used to help ______ the number of variables created

reduce

14
New cards

Methods

instruct an object to perform some action

15
New cards

my_list.append(‘m’)

adds the value ‘m’ to the end of the list

16
New cards

my_list.pop(1)

removes the element at index 1

17
New cards

my_list.remove(‘m’)

removes the first element whose value is ‘m’

18
New cards

Sequence-type functions and methods

built-in functions and methods that operate on sequences like lists and strings

19
New cards

max(my_list)

finds the element in the list with the largest value (even letters have values)

20
New cards

min(my_list)

finds the element in the list with the smallest value

21
New cards

sum(my_list)

finds the total of all elements of a list (numbers only)

22
New cards

my_list.index(‘m’)

finds the index of the first element that matches the value ‘m’

23
New cards

my_list.count(‘m’)

finds how many times the value ‘m’ is in the list

24
New cards

my_list.extend([4, 12])

adds all items (4 & 12) to the list

25
New cards

my_list = [3, 5]

my_list.insert(3, 8)

inserts value 8 into position before 3

my_list = [8, 3, 5]

26
New cards

my_list = [4, 3, 7, 5]

my_list.sort()

puts the elements in order

my_list = [3, 4, 5, 7]

27
New cards

my_list.reverse()

reverses the order of elements in the list

28
New cards

Slice notation

to read multiple elements from a list, creating a new list that contains only the desired elements (EX. my_list[0:2])

29
New cards

Negative indices can be used to count _________ from the end of the list (my_list[0,-1])

backwards

30
New cards

Stride

indicates how many elements are skipped between extracted items in the list (EX. my_list[0:5:2])

31
New cards

List nesting

embedding a list inside another list

EX. my_list = [3, [5, 13], 8]

32
New cards

Programmers can access all elements of nested lists by using…

nested for loops

33
New cards

split()

divides a string into a list of tokens

34
New cards

Token

a substring that forms a part of a larger string

35
New cards

Separator

a character that indicates where to split the string into tokens (EX. string.split(‘#’))

36
New cards

join()

performs the inverse operation of split to create a single string

37
New cards

Parameters

variables listed inside parentheses in a function

38
New cards

Arguments

actual values passed to a function when called