Intro To Lists Flashcards

1
Q

How do you create a list?

A

Square brackets [ ]

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

Every item in a list is a (blank), so each should be enclosed with a (blank)

A

Python string
Quotation mark

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

Name 3 things a “[ ]” will make it easier to do.

A
  1. Get an item at a specified position (1st, 2nd, 3rd etc)
  2. Check the number of items
  3. Add/remove items
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you count the number of entries in a list?

A

len()

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

Referring to any item in the list according to its position in the list is called what?

A

Indexing

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

How would you pull the first entry in a list?

A

[0]

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

How would you pull the second entry in a list?

A

[1]

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

How would you pull the last entry in a list?

A

Use one less than the length of the list

(e.g if the length of list is 10, index using 9)

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

How would you print multiple strings in Python with a single command?

A

Separate them with a comma

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

Pulling a segment of list is called?

A

Slicing

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

To pull the first 3 items in a list what would you use?

A

[ :3]

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

If you wanted the last 4 items in a list what would you use?

A

[-4: ]

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

How would you remove an item from a list?

A

.remove()

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

How would you add an item to a list?

A

.append()

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

What does this tell you?

print(“blank:” , sum(hardcover_sales[ :5]) /5)

A

You want to take the hardcover sales in first five days and divide it by 5

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

What does split() method do?

A

Splits a string into a list

17
Q

How would you quickly turn a string into a list?

A

.split()

18
Q

Indexing is used to

A

Obtain individual elements

19
Q

Slicing is used to

A

Obtain a sequence of elements

20
Q

Lists in Python represent what?

A

Ordered sequences of values

21
Q

How would you access an element at the end of the list?

A

[-1]

22
Q

How would you express wanting all the letters from index 3 onward?

[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’]

A

Letters[3:]

23
Q

Strings will be sorted how?

A

Alphabetically

24
Q

Numbers are sorted how?

A

Numerically

25
Q

A function attached to an object is called a what?

A

Method

26
Q

Non-function things attached to an object, such as imag, are called what?

A

Attributes

27
Q

What is an imag

A

An imaginary part of a #

28
Q

What does list.pop do?

A

Removes and returns the last element of a list

29
Q

Returns the index number at which a particular element appears in a list

A

list.index

30
Q

To avoid surprises, what will the ‘in’ operator determine?

A

Whether a list contains a particular value

“Earth” in planets

True

31
Q

How do you create a tuple?

A

() parenthesis

32
Q

Are tuples immutable?

A

Yes meaning they cannot be modified