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
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,”cloud”] print(Samlist [-1])
["cloud"]
26
What is the output of the list example below? Samlist = [5,8,2,6,4] print(Samlist[-3])
[2]
27
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,”cloud”,"sky"] print(Samlist [-4:-1])
[“moon”,”star”,”cloud”]
28
What is the output of the list example below? Samlist = [5,8,2,6,4] print(Samlist[-5:-2])
[5,8,2]
29
Refer to the item name to change the value of a specific item. (True or False)
F Refer to the index number to change the value of a specific item.
30
Change Item Value in list syntax:
Additem[index]= new_item_value_inthelist.
31
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,”cloud”,"sky"] Samlist [3] = "rain" print(Samlist)
[“sun”, “moon”,”star”,”rain”,"sky"]
32
What is the output of the list example below? Samlist = [5,8,2,6,4] Samlist [4] = 7 print(Samlist)
[5,8,2,6,7]
33
Using a ______ loop, you can loop the items in the list. while for nested
for
34
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,”cloud”,"sky"] for x in Samlist: .....print(x)
``` sun moon star cloud sky ```
35
What is the output of the list example below? Samlist = [5,8,2,6,4] for a in Samlist: .....print(a)
``` 5 8 2 6 4 ```
36
Use the _____ keyword, to determine or check if a specified item is present in the list. in not is as
in
37
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")
Yes, moon is in the list
38
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") ```
3 is not in the list
39
Use the _______ function, to determine how many items a list has. index len count
len
40
Use the ______ method, to add an item at the specified index. append index insert
insert
41
To remove the specified item in a list, use the ______ method. remove () pop() clear() count()
remove ()
42
to remove an item in the specified index in a list use the ______ keyword.
del
43
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()
pop()
44
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,"sky"] Samlist.remove("star") print(Samlist)
[“sun”, “moon”,"sky"]
45
What is the output of the list example below? Samlist = [5,8,2,6,4,7,3] Samlist.pop() print(Samlist)
[5,8,2,6,4,7]
46
What is the output of the list example below? Samlist = [5,8,2,6,4,7,3] Samlist.pop(4) print(Samlist)
[5,8,2,6,7,3]
47
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,"sky"] del Samlist[1] print(Samlist)
[“sun”,”star”,"sky"]
48
What is the output of the list example below? Samlist = [5,8,2,6,4,7,3] del Samlist[4] print(Samlist)
[5,8,2,6,7,3]
49
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,"sky"] Samlist.clear print(Samlist)
[]
50
Use the ________ function, to return the number of times an item appears in the list. remove () pop() clear() count()
count()
51
The _______ method will empty the list. remove () pop() clear() count()
clear()
52
Use ________ method to return the items of the list in reverse order reverse() sort() extend() copy()
reverse()
53
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,"star","sky"] X = Samlist.count("star") print(X)
2
54
What is the output of the list example below? Samlist = [5,8,2,6,4,7,3] X = Samlist.count(1) print(X)
0
55
Use ____ method to return the items of the list in ascending order. reverse() sort() extend() copy()
sort()
56
Use ____ method to add the elements of a list to the end of the current list reverse() sort() extend() copy()
extend()
57
Use ____ method to copy the list. reverse() sort() extend() copy()
copy()
58
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,"sun"] Samlist.reverse() print(Samlist)
[“sun”,”star”, “moon”,"sun"]
59
What is the output of the list example below? Samlist = [5,8,2,6,4,7,3] Samlist.reverse() print(Samlist)
[3,7,4,6,2,8,5]
60
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”,"sun"] Samlist.sort() print(Samlist)
[ “moon”,”star”,“sun”,"sun"]
61
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”] Addlist = ["rain","snow"] Samlist.extend(Addlist) print(Samlist)
[“sun”, “moon”,”star”,"rain","snow"]
62
What is the output of the list example below? Samlist = [“sun”, “moon”,”star”] Copylist = Samlist.copy() print(Copylist)
[“sun”, “moon”,”star”]
63
A list is/can: Ordered Changeable Duplicate Member Indexed
Ordered Changeable Duplicate Member Indexed
64
A Dictionary is/can: Ordered Changeable Duplicate Member Indexed
Changeable | Indexed
65
A Tuples is/can: Ordered Changeable Duplicate Member Indexed
Ordered Duplicate Member Indexed
66
A Sets is/can: Ordered Changeable Duplicate Member Indexed
Changeable
67
a collection which is ordered and unchangeable.
Tuples
68
is a collection written with round () brackets
Tuples
69
In tuples index starts with 0 | True or False
T
70
The syntax below is a ______: Var_name=( , , , ….)
tuple
71
What is the output of the tuple example below? Samtuple= (“summer”, “winter”,”fall”,"spring") print(Samtuple[2])
fall
72
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) print(Samtuple[3])
4
73
What is the output of the tuple example below? Samtuple= (“summer”, “winter”,”fall”,"spring") print(Samtuple[1:3])
(“winter”,”fall”)
74
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) print(Samtuple[2:4])
(3,4)
75
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) print(Samtuple[2:])
(3,4,5)
76
What is the output of the tuple example below? Samtuple= (“summer”, “winter”,”fall”,"spring") print(Samtuple[-2])
fall
77
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) print(Samtuple[-3:-1])
(3, 4)
78
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) for x in Samtuple: .....print(x)
``` 1 2 3 4 5 ```
79
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) print(len(Samtuple))
5
80
Like lists, you can add more items to a tuple once it is created (True or False)
F Tuples are immuttable/unchangeable. You cannot add items to it once tuple is created
81
You cannot remove items in a tuple but you can delete the tuple completely (True or False)
T
82
use the _______ keyword to delete the tuple completely. del index count plus (+)
del
83
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) del Samtuple print(len(Samtuple))
error the tuple is not defined
84
For tuples, use the ______ method to search for the first occurrence of the value and return the index position del index count plus (+)
index
85
What is the output of the tuple example below? Samtuple= (1,2,3,4,5) print(Samtuple.index(2))
1
86
For tuples, use the ______ method to return the number of time an item occurs in a tuple del index count plus (+)
count
87
For tuples, use the ______ operator to join two or more tuples. del index count plus (+)
plus (+)
88
a collection which is unordered and unindexed.
Sets
89
Sets are written with ________ brackets
curly {}
90
The syntax below is a ______: Var_name={ , , , ….}
Set
91
since is ______ unindexed and unordered, you cannot access items in a set by referring to an index. set list tuple
set
92
An iteration can be used through the set of items or use in keyword to specify an item in the sets. (True or False)
T
93
Once a set is created, you cannot change its items. | True or False
T
94
What is the output of the list example below? Samlist = [5,8,2,6,4,7,3] Samlist[2]= 3 print(Samlist)
[5,8,3,6,4,7,3] | The item in index 2 is replaced by 3
95
______ function: converts tuple to list
list()
96
______ function: converts list to tuple
tuple()
97
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() ```
append()
98
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() ```
index(item)
99
used to insert item at position index in the list ``` append() index(item) insert(index, item) sort() remove(item) reverse() ```
insert(index, item)
100
used to sort the elements of the list in ascending order ``` append() index(item) insert(index, item) sort() remove(item) reverse() ```
sort()
101
removes the first occurrence of item in the list ``` append() index(item) insert(index, item) sort() remove(item) reverse() ```
remove(item)
102
reverses the order of the elements in the list ``` append() index(item) insert(index, item) sort() remove(item) reverse() ```
reverse()
103
_______ built-in functions that returns the item that has the lowest or highest value in a sequence
min and max functions
104
use the _______ method to add multiple items to the set. update() discard() difference() intersection()
update()
105
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()
intersection()
106
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()
difference()
107
use the _______ method to remove the specified item from both sets. update() discard() difference() intersection()
discard()
108
What is the output of the tuple example below? Samtuple1= (1,2,3) Samtuple2= (4,5) Samtuple1 = Samtuple1 + Samtuple2 print(Samtuple1)
(1, 2, 3, 4, 5) combining tuples
109
What is the output of the set example below? Samset= {1,2,3} Samset.add(4) print(Samset)
{1, 2, 3, 4}