Data Structures in Python
- Tuples
- Tuples are immutable
- They can not be changed.
- This is (I assume) in support of functional programming.
- They don't like to change data values.
- a = (3,4,5)
- Common Operations
- I really don't use tuples that often.
- Sets
- These are sets
- IE they only have one of each item.
- s = {1, 1, 2, 3, 4, 4, 4}
- union, and intersection
- As methods .union, .intersection
- As operators |, &
- set() produces an empty set.
- Using a set, can you produce a list of unique words in a file?
- string.lower() and string.isalpha()
- string.split(), string.strip()
- sorted()
- set.union
- Lists
- An 0 - indexed array
- [] declares an empty list
- .append, .extend
- Dictionaries
- {}
- {'key':value, 'key':value}
- .keys(), .values()
- If you want to make a module
- Just put it into a file.
- import file brings the entire thing in
- But you need to dereference filename.function
- import file as shortname
- from file import name
- from file import *
- if __name__ == "__main__":