Structured Types
No description yet. This curated deck is ready for daily study.
Card preview (11)
Tubles
• an ordered sequence of elements • immutable • represented with parentheses
Tubles - more
• Swap variables (x, y) = (y, x) - Return more than one value from a function
Lists
• Ordered sequence of information • Denoted by square brackets • Contains a list of elements • Is mutable
Functions as Objects
first class objects: • have types • can be elements of data structures like lists • can appear in expressions • as part of an assignment statement • as an argument to a function! • useful to use functions as arguments when coupled with lists -> higher order programming (hop)
Generalization of HOPs
• Python provides a general purpose HOP -> map • simple form is a unary • general from is an n-ary
Dictionary
Store pairs of data: • key • value
Dictionary lookup
• similar to indexing into a list • looks up the key • returns the value associated with the key • if key not found -> error
Dictionary - values
• immutable and mutable • can be duplicates • can be lists, tuples, dictionaries
Dictionary - keys
• Unique • immutable • careful with using floats! • no order to keys or values!
list vs dictionary
lists: - ordered, look-up by int. index, indices have an order, index is an integer dict: - matches 'keys' to 'values' - look-up one item by another item - no order is guaranteed - key can be any immutable type
global variables
can be dangerous - breaks the scope - allows for side effects BUT can be convenient when want to keep track of information inside a function