PY LISTS Flashcards

1
Q

What is the purpose of Lists?

A

to store multiple items in a single variable

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

What ate the 3 in built data types to store data and info

A

tuple, set, dictinary

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

What are the characteristics of the List items

A

changeable, duplicate, indexed/ ordered
- indexed implies they have fixed order and any new item is added to the end of the list
- dupilcate values are allowed because lits are indexed
- changeable: we can delete, edit, add things to the list after it has been created

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

_____ is the index number of the 1st list item

A

0

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

_____ is another way of producing a list using doble round brackets

A

list constructor

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

How can we access specific list items?

A

index numbers

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

how can we obtain the last item or the ones preceding it in a list?

A

print(list[len(list)-1])
OR
We can do negative indexing

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

[:6] when such a command has been produced what kind of output should we expect?

A

the output will start from 1st item and exclude the end value

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

what output to expect with this command[2:]

A

the output will include the index item 2 and go on till the end

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

____ keyword is used to determine if a specified item is present in the list

A

in

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

how can we change.a specific item in the list

A

mylist[2] = “kd”
so the output will replace that index item with the new one

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

how to change multiple items in the list?

A

using a range of index when producing the command for new words
list{2:4} = new items

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

when will the length of the list change?

A

When number of items inserted does not match the no. of items replaced and the items will get adjusted accordingly

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

if i replace more items than i insert, what will happen
eg;
mylist=[pen, pencil,pin,kit,kat]
mylist[2:4]=[book}

A

then items in the range index will change rest will get adjusted to it i.e. items in the position of 2 and 3 index values will get replaced by the sing;e item book

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

____ fxn increases the list items without changing the items

A

mylist.insert(index number, “item”)
it increased the items in the list

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

Use____ function to add items to the end of the list

A

append()

17
Q

___ fxn removes the item from the list

A

remove()

18
Q

____ method removes the specified index number

A

pop()

19
Q

Which method arrange the list in ascending order by default

A

sort()

20
Q

how canwe produce numbers arrnaged in descending order

A

list.sort(reverse=True)

21
Q

How to count a specified item in the list?

A

.count(“item”)

22
Q

____ fxn will produce a reversed order of the list

A

.reverse()

23
Q

how to add items to the end of the list

A

.extend()