Module 1: Collections: List, Tuples, Set Flashcards

1
Q

_________ is a built-in python module that provides useful container datatypes.

A

Collections

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

_________ datatypes allow us to store and access values in a convenient way.

A

Container

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

_________ in Python are containers that are used to store collections of data, for example, list, dict, set, tuple etc. and they are under the built-in collections.

A

Collections

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

a collection which is ordered and changeable, are written with square [ ] brackets

A

List

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

In list, index starts with 1, items are separated with comma

True or False

A

F

index starts with 0, items are separated with comma

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

lists include double quotation if the item is string

True or False

A

T

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

The syntax below belongs to the ________ collection:

var_name = [ , , , ….]

A

List

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

Samlist = [“sun”, “moon”,”star”,”cloud”] -> string values

The index of “moon” is _______

A

1

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

access the list items by referring to the _______ number

A

index

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

Samlist = [5,8,2,5,4] –> are ________ values

A

non-string

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

Samlist = [“sun”, “moon”,”star”,”cloud”] -> are _______ values

A

string

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

You can access list items by referring to the ________

index number
item
key
value

A

index number

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”cloud”]
print(Samlist [2])

A

[“star”]

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

What is the output of the list example below?

Samlist = [5,8,2,5,4]
print(Samlist[3])

A

[6]

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

in ________ you need to specify the range of indexes by specifying where to start and where to end the range. The return value will be a new list in the specified items

A

accessing range of items

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

Access range of items syntax:

A

print (var_list[start_index : end_index])

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

What is the output of the list example below?

Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[2:6])

A

[2,6,4,1]

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

What is the output of the list example below?

Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[0:2])

A

[5,8]

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

accessing range of items without a start or end index. syntax:

A

print (var_list[: end_index])

start with index 0

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

In the syntax:

print (var_list[: end_index])

the range will go on to the ______ of the list

A

end

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

What is the output of the list example below?

Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[:4])

A

[5,8,2,6]

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

What is the output of the list example below?

Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[5:])

A

[1,3,7,9]

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

means beginning from the end, means -1 refers to the last item of the list, -2 refers to the second last item and so on.

A

Negative indexing

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

______ of negative indexing needs to specify the negative indexes if you want to start the search form the of the list.

A

Range

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”cloud”]
print(Samlist [-1])

A

[“cloud”]

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

What is the output of the list example below?

Samlist = [5,8,2,6,4]
print(Samlist[-3])

A

[2]

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”cloud”,”sky”]
print(Samlist [-4:-1])

A

[“moon”,”star”,”cloud”]

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

What is the output of the list example below?

Samlist = [5,8,2,6,4]
print(Samlist[-5:-2])

A

[5,8,2]

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

Refer to the item name to change the value of a specific item.
(True or False)

A

F

Refer to the index number to change the value of a specific item.

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

Change Item Value in list syntax:

A

Additem[index]= new_item_value_inthelist.

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”cloud”,”sky”]
Samlist [3] = “rain”
print(Samlist)

A

[“sun”, “moon”,”star”,”rain”,”sky”]

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

What is the output of the list example below?

Samlist = [5,8,2,6,4]
Samlist [4] = 7
print(Samlist)

A

[5,8,2,6,7]

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

Using a ______ loop, you can loop the items in the list.

while
for
nested

A

for

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”cloud”,”sky”]
for x in Samlist:
…..print(x)

A
sun
moon
star
cloud
sky
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4]
for a in Samlist:
…..print(a)

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

Use the _____ keyword, to determine or check if a specified item is present in the list.

in
not
is
as

A

in

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”cloud”,”sky”]
if “moon” in Samlist:
…..print(“Yes, moon is in the list”)

A

Yes, moon is in the list

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

What is the output of the list example below?

Samlist = [5,8,2,6,4] 
if 3 in Samlist:
.....print("3 is in the list")
else:
.....print("3 is not in the list")
A

3 is not in the list

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

Use the _______ function, to determine how many items a list has.

index
len
count

A

len

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

Use the ______ method, to add an item at the specified index.

append
index
insert

A

insert

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

To remove the specified item in a list, use the ______ method.

remove ()
pop()
clear()
count()

A

remove ()

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

to remove an item in the specified index in a list use the ______ keyword.

A

del

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

In a list, to remove the item in the specified index or the last item if index is not specified, use the ______ method

remove ()
pop()
clear()
count()

A

pop()

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

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”sky”]
Samlist.remove(“star”)
print(Samlist)

A

[“sun”, “moon”,”sky”]

45
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4,7,3]
Samlist.pop()
print(Samlist)

A

[5,8,2,6,4,7]

46
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4,7,3]
Samlist.pop(4)
print(Samlist)

A

[5,8,2,6,7,3]

47
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”sky”]
del Samlist[1]
print(Samlist)

A

[“sun”,”star”,”sky”]

48
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4,7,3]
del Samlist[4]
print(Samlist)

A

[5,8,2,6,7,3]

49
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”sky”]
Samlist.clear
print(Samlist)

A

[]

50
Q

Use the ________ function, to return the number of times an item appears in the list.

remove ()
pop()
clear()
count()

A

count()

51
Q

The _______ method will empty the list.

remove ()
pop()
clear()
count()

A

clear()

52
Q

Use ________ method to return the items of the list in reverse order

reverse()
sort()
extend()
copy()

A

reverse()

53
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”star”,”sky”]
X = Samlist.count(“star”)
print(X)

A

2

54
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4,7,3]
X = Samlist.count(1)
print(X)

A

0

55
Q

Use ____ method to return the items of the list in ascending order.

reverse()
sort()
extend()
copy()

A

sort()

56
Q

Use ____ method to add the elements of a list to the end of the current list

reverse()
sort()
extend()
copy()

A

extend()

57
Q

Use ____ method to copy the list.

reverse()
sort()
extend()
copy()

A

copy()

58
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”sun”]
Samlist.reverse()
print(Samlist)

A

[“sun”,”star”, “moon”,”sun”]

59
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4,7,3]
Samlist.reverse()
print(Samlist)

A

[3,7,4,6,2,8,5]

60
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”,”sun”]
Samlist.sort()
print(Samlist)

A

[ “moon”,”star”,“sun”,”sun”]

61
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”]
Addlist = [“rain”,”snow”]
Samlist.extend(Addlist)
print(Samlist)

A

[“sun”, “moon”,”star”,”rain”,”snow”]

62
Q

What is the output of the list example below?

Samlist = [“sun”, “moon”,”star”]
Copylist = Samlist.copy()
print(Copylist)

A

[“sun”, “moon”,”star”]

63
Q

A list is/can:

Ordered
Changeable
Duplicate Member
Indexed

A

Ordered
Changeable
Duplicate Member
Indexed

64
Q

A Dictionary is/can:

Ordered
Changeable
Duplicate Member
Indexed

A

Changeable

Indexed

65
Q

A Tuples is/can:

Ordered
Changeable
Duplicate Member
Indexed

A

Ordered
Duplicate Member
Indexed

66
Q

A Sets is/can:

Ordered
Changeable
Duplicate Member
Indexed

A

Changeable

67
Q

a collection which is ordered and unchangeable.

A

Tuples

68
Q

is a collection written with round () brackets

A

Tuples

69
Q

In tuples index starts with 0

True or False

A

T

70
Q

The syntax below is a ______:

Var_name=( , , , ….)

A

tuple

71
Q

What is the output of the tuple example below?

Samtuple= (“summer”, “winter”,”fall”,”spring”)
print(Samtuple[2])

A

fall

72
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
print(Samtuple[3])

A

4

73
Q

What is the output of the tuple example below?

Samtuple= (“summer”, “winter”,”fall”,”spring”)
print(Samtuple[1:3])

A

(“winter”,”fall”)

74
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
print(Samtuple[2:4])

A

(3,4)

75
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
print(Samtuple[2:])

A

(3,4,5)

76
Q

What is the output of the tuple example below?

Samtuple= (“summer”, “winter”,”fall”,”spring”)
print(Samtuple[-2])

A

fall

77
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
print(Samtuple[-3:-1])

A

(3, 4)

78
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
for x in Samtuple:
…..print(x)

A
1
2
3
4
5
79
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
print(len(Samtuple))

A

5

80
Q

Like lists, you can add more items to a tuple once it is created
(True or False)

A

F

Tuples are immuttable/unchangeable. You cannot add items to it once tuple is created

81
Q

You cannot remove items in a tuple but you can delete the tuple completely
(True or False)

A

T

82
Q

use the _______ keyword to delete the tuple completely.

del
index
count
plus (+)

A

del

83
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
del Samtuple
print(len(Samtuple))

A

error

the tuple is not defined

84
Q

For tuples, use the ______ method to search for the first occurrence of the value and return the index position

del
index
count
plus (+)

A

index

85
Q

What is the output of the tuple example below?

Samtuple= (1,2,3,4,5)
print(Samtuple.index(2))

A

1

86
Q

For tuples, use the ______ method to return the number of time an item occurs in a tuple

del
index
count
plus (+)

A

count

87
Q

For tuples, use the ______ operator to join two or more tuples.

del
index
count
plus (+)

A

plus (+)

88
Q

a collection which is unordered and unindexed.

A

Sets

89
Q

Sets are written with ________ brackets

A

curly {}

90
Q

The syntax below is a ______:

Var_name={ , , , ….}

A

Set

91
Q

since is ______ unindexed and unordered, you cannot access items in a set by referring to an index.

set
list
tuple

A

set

92
Q

An iteration can be used through the set of items or use in keyword to specify an item in the sets.

(True or False)

A

T

93
Q

Once a set is created, you cannot change its items.

True or False

A

T

94
Q

What is the output of the list example below?

Samlist = [5,8,2,6,4,7,3]
Samlist[2]= 3
print(Samlist)

A

[5,8,3,6,4,7,3]

The item in index 2 is replaced by 3

95
Q

______ function: converts tuple to list

A

list()

96
Q

______ function: converts list to tuple

A

tuple()

97
Q

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

append()
index(item)
insert(index, item)
sort()
remove(item)
reverse()
A

append()

98
Q

used to determine where an item is located in a list. Returns the index of the first element in the list containing item

append()
index(item)
insert(index, item)
sort()
remove(item)
reverse()
A

index(item)

99
Q

used to insert item at position index in the list

append()
index(item)
insert(index, item)
sort()
remove(item)
reverse()
A

insert(index, item)

100
Q

used to sort the elements of the list in ascending order

append()
index(item)
insert(index, item)
sort()
remove(item)
reverse()
A

sort()

101
Q

removes the first occurrence of item in the list

append()
index(item)
insert(index, item)
sort()
remove(item)
reverse()
A

remove(item)

102
Q

reverses the order of the elements in the list

append()
index(item)
insert(index, item)
sort()
remove(item)
reverse()
A

reverse()

103
Q

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

A

min and max functions

104
Q

use the _______ method to add multiple items to the set.

update()
discard()
difference()
intersection()

A

update()

105
Q

use the _______ method to return a set that contains the items that exist in both set x and in set y.

update()
discard()
difference()
intersection()

A

intersection()

106
Q

use the _______ method to return a set that contains the items that only exist in set x and not in set y.

update()
discard()
difference()
intersection()

A

difference()

107
Q

use the _______ method to remove the specified item from both sets.

update()
discard()
difference()
intersection()

A

discard()

108
Q

What is the output of the tuple example below?

Samtuple1= (1,2,3)
Samtuple2= (4,5)
Samtuple1 = Samtuple1 + Samtuple2
print(Samtuple1)

A

(1, 2, 3, 4, 5)

combining tuples

109
Q

What is the output of the set example below?

Samset= {1,2,3}
Samset.add(4)
print(Samset)

A

{1, 2, 3, 4}