• Skip to primary navigation
  • Skip to main content

DebKR

To the Stars

  • About
  • Blog
  • Contact

items()

Coding 101 (part 8)

Coding 101 (part 8)

03/05/2016 By debkr

A quick recap:
We’re cracking on well here, going through the Python course on Coursera as taught by Dr. Chuck (see footnotes for more info and links). We’ve looked a strings and how we can slice, dice and extract data from them using find and split functions. We’ve gone on to learn about files, and proceeded to open and read data from files, both as strings and as lists. We’ve been able to index lists using integer values from zero upwards. Then we’ve gone on to look at dictionaries, which are mini two-field databases of key/value pairs referenced using their keys. And all throughout we’ve been learning about and using various kinds of loops or iterations, conditional statements, and functions (both built-in and defined in-program).

Monty_Python,_And_Now_for_Something_Completely_Different_(1971)And now for something completely different:
All these things were familiar to me from programming in school and as a maths undergrad (albeit a little rusty!). But now we come on to something completely different, something I hadn’t heard of before: tuples. I’ll call tuples the big brother of lists as they’re very similar to lists: they’re basically another type of collection of things. [Read more…] about Coding 101 (part 8)

Filed Under: Blog, Personalised Training Plan, Programming Tagged With: append(), argument, coding101, count, dictionary, function, items(), key/value pair, list, loop, order, python, sort, tuple

Coding 101 (part 7)

Coding 101 (part 7)

29/04/2016 By debkr

coding-101-dictionariesLists work great but they leave something on the table:
I’ve been building a Tagging Engine in Python as a little exercise to help me learn by doing, using my knowledge so far. It became clear pretty quickly that I needed a better way to handle pairs of data. In this case I was looking at a list of words and the number of times each of them appeared in a text, so that I could rank the most common words by order of significance (frequency). If I just used one list and appended both the word and its count to the list, one value after the other, there was no way I could sort by count number.

I got round this problem by having two lists, one for the words and another for the word counts. I could then manipulate the data as needed. This did work fine in the simple program I wrote, but it was my usual unwieldy, sledgehammer approach again. I knew there was a way I could handle that pair of data points better – using Python’s Dictionaries functionality – but I didn’t want to rush ahead of the curve. Well now I get the chance to learn all about dictionaries. [Read more…] about Coding 101 (part 7)

Filed Under: Blog, Personalised Training Plan, Programming Tagged With: coding101, count, data, database, dict(), dictionary, function, items(), key/value pair, list, order, python, return, value, variable, word counts

Coding 101 (part 3)

Coding 101 (part 3)

04/04/2016 By debkr

This post follows on from my earlier posts Coding 101 (part 1) and (part 2), and is my responses and learnings from the highly-recommended Python programming book and course by Charles Severance (see References below).

Functions:
Functions are sections of code (a sequence of executable steps) which we want to be able to use and re-use at many points in our program. It may be that we want to read and process a whole range of data over and over (but the process done to all the data is the same) or maybe there are a number of inputs required from the user which all need to be processed the same way. Rather than rewriting the same lines of code again and again in our program, we can give that section of code a name (known as ‘defining the function’). We can then ‘call’ that named function, that is, ask Python to execute the defined sequence of steps, at any future point within our program, and as many times as we want. (In other programming languages this same functionality may be referred to as sub-programs or sub-routines.) [Read more…] about Coding 101 (part 3)

Filed Under: Blog, Personalised Training Plan, Programming Tagged With: ==, argument, break, code, coding101, condition, construct, continue, data, define, function, input, items(), iteration, largest, list, loop, parameter, program, python, raw_input, reserved words, return, sequence, smallest, string, type, value, variable

Copyright © 2016–2025 · Powered by WordPress On Genesis Framework · Log in

  • Writing
  • Developing
  • Consulting