When strings become spaghetti:
Working with strings and files, particular when using the for {line} in {filehandle}: construct, allows us to do some cool manipulation of data, by finding, splitting and stripping the data into different chunks based on some repeating factor (such as a comma spearating each value in order), then sorting, counting and totalling those values through iterative loops. [Read more…] about Coding 101 (part 6)
startswith()
Coding 101 (part 5)
This post follows on from earlier Coding 101 posts and records my responses and learnings from the highly-recommended Python programming book and Coursera specialisation by Charles Severance (see References below).
Opening data files:
In all our previous examples we used data as a constant (i.e. hard-coded into the program some way) or we prompted the user to enter some data which was then manipulated by the program in some way. We want to be able to read data from a variety of sources though – either from files, or from the web – and we know these are going to be much larger data sources, so we’ll need to be able to access and save files on our hard drive somewhere. [Read more…] about Coding 101 (part 5)
Coding 101 (part 4)
This post follows on from earlier posts (Coding 101 (part 1) ~ (part 2) ~ (part 3)) and records my responses and learnings from the highly-recommended Python programming book and Coursera specialisation by Charles Severance (see References below).
A quick recap on strings:
Strings are computer-speak for characters, specifically where some object or value has the ‘type’ string. Type is an attribute Python applies to any given object or value so it knows how to handle that object or value, i.e. what kinds of operations can and cannot be applied to it. String, and two numeric types – integer and float – are the most common types within Python.
A string may contain one or more characters, so ‘a’ and ‘0’ are strings, just as ‘abcdefghij’ and ‘Hello world. I am Python.’ are. [Read more…] about Coding 101 (part 4)