Lecture 5 - Lists Flashcards
Lists are ____ and ____ type of objects
mutable, container
What are the similarities between lists and strings
- 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
What are the differences between lists and strings
• 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
What is the difference between x.sort and sorted (x)
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.
Range
range (start, stop, stride)
you always include the start value and always exclude the stop value
NEVER TAKE THE STOP VALUE