Exam 2 Review for Python :(

5.0(1)
studied byStudied by 4 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/149

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

150 Terms

1
New cards

dictionary

object that stores a collection of data

2
New cards

key

the immutable identity for the element in a dictionary

3
New cards

dictionary = {key1:value1}

format for creating a dictionary

4
New cards

false

true or false: dictionaries are sorted

5
New cards

dictionary[key]

general format for retrieving value from dictionary

6
New cards

true

true or false: a keyerror is returned if you call a dictionary with a nonexistent key

7
New cards

in

operator used to test whether a key is in a dictionary

8
New cards

true

true or false: dictionaries are mutable

9
New cards

dictionary[key]=value

format to add or change a key-pair value in a dictionary

10
New cards

del dictionary[key]

format to delete a key-value pair

11
New cards

len function

used to obtain number of elements in a dictionary

12
New cards

true

true or false: Values stored in a single dictionary can be of different types

13
New cards

dict()

built in function that creates an empty dictionary

14
New cards

clear method

deletes all the elements in a dictionary, leaving it empty

15
New cards

get method

gets a value associated with specified key from the dictionary

16
New cards

dictionary.get(key, default)

format for get method (returns default if key is not found)

17
New cards

items method

returns all the dictionaries keys and associated values; Each element in dictionary view is a tuple which contains a key and its associated value

18
New cards

keys method

returns all the dictionaries keys as a sequence

19
New cards

pop method

returns value associated with specified key and removes that key-value pair from the dictionary

20
New cards

dictionary.pop(key, default)

format for pop method; default is returned if key not found

21
New cards

popitem method

returns a randomly selected key-value pair as a tuple and removes that key-value pair from the dictionary

22
New cards

values method

returns all the dictionaries values as a sequence

23
New cards

set

object that stores a collection of data in same way as mathematical set

24
New cards

false

true or false: sets cannot have elements of different data types

25
New cards

set()

format of function used to create an empty set

26
New cards

‘a’,’b’,’c’

what a set contains if set(‘abc’) is passed

27
New cards

‘abc’

what a set contains if set([‘set’])

28
New cards

true

true or false: sets are mutable

29
New cards

add method

adds an element to a set

30
New cards

update method

adds a group of elements to a set

31
New cards

remove method

removes the specified item from the set WITH CAUSING A KEYERROR

32
New cards

discard method

removes the specified item from the set WITHOUT CAUSING A KEYERROR

33
New cards

clear method

clears all the elements of the set

34
New cards

union of two sets

a set that contains all the elements of both sets

35
New cards

set1.union(set2)

union method format

36
New cards

set1 l set2

operator for union method

37
New cards

intersection of two sets

a set that contains only the elements found in both sets

38
New cards

set1.intersection(set2)

format for intersection method

39
New cards

set1 & set2

operator for intersection method

40
New cards

difference of two sets

a set that contains the elements that appear in the first set but do not appear in the second set

41
New cards

set1.difference(set2)

difference method format

42
New cards

set1 - set2

difference method operator

43
New cards

Symmetric difference of two sets

a set that contains the elements that are not shared by the two sets

44
New cards

set1.symmetric_difference(set2)

symmetric_difference method format

45
New cards

set1 ^ set2

symmetric_difference method operator

46
New cards

subset

small set that is in a bigger set

47
New cards

superset

a large set that contains all the elements of a smaller set

48
New cards

setA.issubset(setB)

To determine whether set A is subset of set B

49
New cards

setA <= setB

To determine whether set A is subset of set B operator

50
New cards

setA.issuperset(setB)

To determine whether set A is superset of set B

51
New cards

setA >= setB

To determine whether set A is superset of set B operator

52
New cards

Serialize an object

convert the object to a stream of bytes that can easily be stored in a file (turning an object into computer words)

53
New cards

pickling

term meaning serializing an object

54
New cards

pickle

what you import to pickle and stuff

55
New cards

pickle.dump(object, file)

function to pickle objects to a file

56
New cards

unpickling

retrieving pickled object

57
New cards

pickle.load(file)

format to get pickled object from a file

58
New cards

{‘a’,’b’,’c’,’d’,’e’,’f’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 | set2

59
New cards

{‘c’,’d’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 & set2

60
New cards

{‘a’,’b’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 - set2

61
New cards

{‘e’,’f’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3= set2- set1

62
New cards

{‘a’,b’,’e’,’f’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 ^ set2

63
New cards

sequence

an object that contains multiple items of data

64
New cards

list

an object that contains multiple data items and is mutible

65
New cards

list(object)

function converting objects to list

66
New cards

element

an item in a list

67
New cards

true

true or false lists can hold items of different types

68
New cards

list=[item1, item2, item3]

format for list assignment statement

69
New cards

repetition operator

makes multiple copies of a list and joins them together

70
New cards

index

a number specifying the position of an element in a list

71
New cards

0

index of first element in a list

72
New cards

-1

index of last element in a list

73
New cards

IndexError

raised if invalid index is used YOU CAN ONLY USE THE INDEX YOU HAVE

74
New cards

len function

returns the length of a sequence such as a list

eg: size = len(my_list)

75
New cards

mutable sequence

a sequence in which the items in the sequence can be changed

76
New cards

list[x] = new_value

format to assign a new value to a list element

77
New cards

concatenate

joining two things together

78
New cards

augmented assignment operator

+= used to concatenate lists

79
New cards

slice

a span of items that are taken from a sequence

80
New cards

list[start:end]

list slice format————-will not include end value

81
New cards

false

true or false, this will cause a IndexError

list=[1,2,3,4,5,6,7,8]

print(list[0:20])

82
New cards

append(item)

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

83
New cards

index(item)

METHOD returning the index of the first element in the list containing item

-raises ValueError if item not in the list

84
New cards

insert(index, item)

METHOD used to insert item at position index in the list

85
New cards

sort()

METHOD used to sort the elements of the list in ascending order

86
New cards

remove(item)

METHOD used to remove the first occurrence of item in list

87
New cards

reverse()

METHOD used to reverse the order of the elements in the list

88
New cards

del list[x]

STATEMENT removing an element from a specific index in a list

89
New cards

min(list)

FUNCTION returning the item that has the lowest value in a sequence

90
New cards

max(list)

FUNCTION returning the item that has the highest value in a sequence

91
New cards

two-dimensional lists

a list that contains other lists as its elements

92
New cards

tuple

an immutable sequence

93
New cards

tuple_name=(item1, item2)

tuple format assignment statement

94
New cards

tuple(list)

turns list into tuple

95
New cards

cookie

a small file that contains information about the browsing session

96
New cards

“writing data to”

saving data on a file

97
New cards

output file

a file that data is written to

98
New cards

“reading data from”

process of retrieving data from a file

99
New cards

input file

a file from which data is read

100
New cards

open the file, process the file, close the file

the three steps when a program uses a file