Lists Flashcards

1
Q

Lists

A

Ordered sequences that can hold a variety of object types

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

.append

A

Add a variable to the end of a list

my_list.append(‘seven’)

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

.pop

A

Pop a variable off a list. Defaults to the last variable, but can be changed with index number

my_list.pop() / my_list.pop(3)

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

.sort

A

Sorts a list in alphabetical or numerical order.

Note: Doesn’t return anything, sorts it in place. Must call the list to see the sorted variables.

my_sorted_list = my_list.sort()
This wont work because of the note above

new_list.sort()
my_sorted_list = new_list
This will work

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

.reverse

A

Puts the variables in a list in reverse order. Just like the .sort function it happens in place and does not return anything unless called.

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

Dictionary vs. List

A

{ } Dictionaries:

  • Unordered and cannot be sorted
  • Objects retrieved by key name

[ ] Lists:

  • Ordered sequence can be indexed or sliced
  • Objects retrieved by key name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly