Lecture 5 - Lists Flashcards

1
Q

Lists are ____ and ____ type of objects

A

mutable, container

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

What are the similarities between lists and strings

A
  • len (counts characters in strings and objects in lists)!
  • indexing
  • slicing
  • appending with + (concatenation)
  • repeating with *
  • may be empty
  • can be compared for equality and ordering
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the differences between lists and strings

A

• strings are immutable, lists are mutable
• strings only contain characters, lists may contain any
object type
• they support many different methods, e.g.
• string has .upper() but list does not
• list supports .append() but string does not

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

What is the difference between x.sort and sorted (x)

A

x.sort ( ) sorts the objects in the memory, mutates the list - permanent sorting
sorted (x) - outputs a sorted list as a result of it (function) being called does not make any changes to the original list.

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

Range

A

range (start, stop, stride)
you always include the start value and always exclude the stop value
NEVER TAKE THE STOP VALUE

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