Functions, namespace, memory management: Difference between revisions
Jump to navigation
Jump to search
| Line 21: | Line 21: | ||
The 2 first exercises are re-use from earlier. It is for a good purpose as will be seen later. | The 2 first exercises are re-use from earlier. It is for a good purpose as will be seen later. | ||
# Make a function '''fastaread(filename)''' which takes a filename as a parameter and returns 2 lists, first list is the headers, second list is the sequences (as single strings without whitespace). Add appropriate error handling to the function. You can test your function on the file ''dna7.fsa''. | # Make a function '''fastaread(filename)''' which takes a filename as a parameter and returns 2 lists, first list is the headers, second list is the sequences (as single strings without whitespace). Add appropriate error handling to the function. You can test your function on the file ''dna7.fsa''. | ||
# Make a function '''fastawrite(filename, headers, sequences)''' which takes a filename, a list of headers and a corresponding list of sequences as parameters and writes the fasta file. Add appropriate error handling to the function. You can test your function on the file ''dna7.fsa''. If you first read the file with '''fastaread'' and then write a new file with '''fastawrite''', then if the files are identicalm you know you have done right. | # Make a function '''fastawrite(filename, headers, sequences)''' which takes a filename, a list of headers and a corresponding list of sequences as parameters and writes the fasta file. Add appropriate error handling to the function. You can test your function on the file ''dna7.fsa''. If you first read the file with '''fastaread''' and then write a new file with '''fastawrite''', then if the files are identicalm you know you have done right. | ||
== Exercises for extra practice == | == Exercises for extra practice == | ||
Latest revision as of 17:05, 27 February 2026
| Previous: Collaborative git | Next: Comprehension, generators, iteration |
Required course material for the lesson
Powerpoint: Functions - this will be short as it is a reminder.
Powerpoint: Namespace.
Powerpoint: Memory management.
Video: Functions in Python
Video: Examples and identifying data types
Resource: Example code - Functions
Video: Live Coding
Subjects covered
- Short about functions
- Namespace in Python
- Memory management
Exercises to be handed in
The 2 first exercises are re-use from earlier. It is for a good purpose as will be seen later.
- Make a function fastaread(filename) which takes a filename as a parameter and returns 2 lists, first list is the headers, second list is the sequences (as single strings without whitespace). Add appropriate error handling to the function. You can test your function on the file dna7.fsa.
- Make a function fastawrite(filename, headers, sequences) which takes a filename, a list of headers and a corresponding list of sequences as parameters and writes the fasta file. Add appropriate error handling to the function. You can test your function on the file dna7.fsa. If you first read the file with fastaread and then write a new file with fastawrite, then if the files are identicalm you know you have done right.