Tools I Used:
- My favorite mini-IDE!
- Python shell / bash shell
- I use the Python shell to learn functions interactively, and the bash shell to execute the scripts I write.
- Date Translator (
- Kind of a bug release, I guess — I fixed a problem where single-digit days were showing up with an unnecessary initial zero.
- Domain Name Translator (
- A simple script that strips the domain name from a URL. Basically just a proof-of-concept to help me understand lists in Python a bit better.
- Quotation Box (
- Takes a line of user input and centers it in a ASCII text box in their terminal.
Functions/Concepts I Learned:
- Lists are essentially sequences of data that you can manipulate in any number of ways — and manipulating data is what programming is all about!
[::]let you index, slice, and choose step size of the slice respectively. These are tools that by themselves only return the value of a list, but can be used in conjunction with other functions can powerfully manipulate lists or parts of lists.
Noneis Python’s concept of, not zero, but nothing at all; it is a null or an unset value. This is useful for filling a list up that you will put data in later.
max()let you check the length of a list, the smallest member in a list, and the largest member in a list respectively.
dellets you delete members from a list.
- I think tuples are a bit above me at this point, but I understand them to be similar to lists, only non-modifiable once created. Useful for dictionaries, or perhaps an internal checksum.
- Methods are really awesome! They are like functions, only you tell methods to work only on specific parts of a sequence, rather than the whole. Several of these can be implemented using slices, but using methods is less ugly looking and much more human-readable.
.appendadds a single data point to the end of a list, while
.extendlets you add multiple data points to the end of a list (including adding other lists).
.countcounts the occurrences of elements in a list, but does not examine sublists (i.e., for
numbers = [1,2,1,1,2],
numbers.count(2)will return 2, but for
numbers = [1,2,1,[1,2]], it would return only 1).
.indexreturns the index value of the first occurrence of your search term in a given list, and
.removewill search for and remove the first occurrence of the term. However, these only deal with the first occurrence — if the value appears multiple times in a list, you will need multiple
.removeoperations to deal with them, or else some other Python function I don’t know about yet.
.popis interesting because it “pops” (i.e., deletes) the last entry in a list out and returns the value. According to Hetland, this is a way to implement a stack, a word which I have heard a lot concerning programming, but have never really heard explained.
.reversereverses the elements in a list (not just returning them reversed like the
.sortsorts the elements in a list in ascending order (not just returning them sorted like the
sortedfunction). You can use the
reversearguments to sort by various other means than the default ascending order.
list()converts a sequence to a list, and
tuple()similarly converts a sequence to a tuple.
cmplets you compare two values, returning 0 for a match, 1 when the first value is larger, and -1 when the first value is smaller.
This week I finally got lists, and it was very rewarding; I feel much more confident to take on the rest of Python now. While I didn’t learn any cool new functions, I learned a lot about how to put lists to work for me, and I think it was worth it. Next week, I will try to get through Hetland’s chapter on strings, and I think it will be similarly devoid of new functions, but I’ll sure learn a lot about how to play around with strings!