Module 4: Strings and Lists are iterables Flashcards

1
Q

A _______ is a collection of items in some order.

A

sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A string is a ______ meaning it is an ordered collection of other values.

A

sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Access characters of a string one at a time using _______.

A

bracket operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

expression in [ ] brackets is _______ and starts at ______.

A

index, 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

value of an index must be _______.

A

integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

______ is a built in function that returns number of characters in a string.

A

len(stringname)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

to get last digit of word from index use [ ______ ] or [ ______ }

A
  1. first: length = len(fruit)
    last length-1
  2. [-1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A _____ is a segment of a string

A

slice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

select a slice using [ _______ ]

A

n:m
:m or n:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A _______ is a pattern that starts at the beginning, select each character in turn, do something to it, and continue until the end.

A

traversal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

strings are _______ meaning you cannot change an existing string and cannot use [ ] on the left side of assignment.

A

immutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A ______ is the pattern of computation of traversing a sequence and returning when we find what we are looking for.

A

search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A list is a sequence of _______. In a string values are _______, in a list they are _______.

A

values, characters, any/elements/items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

empty list is given by ______

A

[ ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

variables can be ________ list values

A

assigned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

syntax for accessing elements of a list is ______ as for accessing characters of a string

A

the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

unlike strings, lists are ______, meaning they can be _______

A

mutable, changed

18
Q

A ______ is commonly used to traverse the elements of a list

A

for loop

19
Q

range(n) returns a sequence of n number from ____ to ____

A

0 to n-1

20
Q

A for loop over an _____ never runs the body.

A

empty list

21
Q

______ takes a value and mutates the list, adding the new element to the end

A

listname.append(value)

22
Q

______ takes a list and mutates the first list, appending all the values in the second list to it.

A

firstlistname.extend(secondlistname)

23
Q

_____ returns another list containing all the same items. It takes ________ arguments.

A

firstlistname.copy()
no

24
Q

______ modifies the list and returns the element that was removed. if an index isnt provided it deletes and returns the last element.

A

firstlistname.pop(#)

25
Q

use _____ to convert from a string to a list of characters

A

list(nameofstring)

26
Q

use ______ to break a string into words

A

firstlistname.split(delimiter)
can use ( ) instead where it will split at spaces

27
Q

______ is an optional argument that specifies which characters to use as word boundaries

A

delimiter

28
Q

_________ takes a list of strings and concatenates the elements. must invoke it on the delimiter and pass the list as a parameter.

A

delimiter.join(firstlistname)

29
Q

______ data types cannot be changed and include _____, ______, _______.

A

immutable, int, float, str

30
Q

use _____ to check whether two variables refer to the same object

A

is

31
Q

a ________ is the association of a variable with an object

A

reference

32
Q

if an aliased object is mutable, changes made to one alias will _______

A

affect the other

33
Q

a tuple is like a list but is _______

A

immutable

34
Q

strings, lists, and range objects are all ________

A

iterables

35
Q

The first value for index is _______ and the last is _______.

A

0
length - 1

36
Q

the len function returns type _______.

A

int

37
Q

To create a boolean expression using in write _______, ________, ________.

A

value, in, iterable such as str or list

38
Q

Use [_____:______:______] to go through a list/string while selecting only certain values.

A

start
stop
step

39
Q

in an index _______ returns the last value

A

-1

40
Q

Create a tuple using _______ brackets. For a tuple with only one object add a _______ after the object. Can convert _______ or _______ to a tuple by _______.

A

round ( )
,
string
list
tuple(“string”) or tuple([list])

41
Q

compared to a list which has _______ argument, a tuple has ________ argument.

A

1
many