Most recent comments
2021 in Books -- a Miscellany
Are, 1 year, 8 months
Moldejazz 2018
Camilla, 4 years, 2 months
Romjulen 2018
Camilla, 4 years, 9 months
Liveblogg nyttårsaften 2017
Tor, 5 years, 9 months
Jogging og blogging
Are, 6 years, 8 months
Liveblogg nyttårsaften 2016
Are, 6 years, 8 months
Kort hår
Tor, 2 years, 9 months
Camilla, 2 years, 3 months
Melody Gardot
Camilla, 4 years, 2 months
Den årlige påske-kommentaren
Tor, 4 years, 5 months
50 book challenge
Camilla, 9 months
Ten years ago
+ 2004
+ 2005
+ 2006
+ 2007
+ 2008
+ 2009
+ 2010
+ 2011
+ 2012
+ 2013
+ 2014
+ 2015
+ 2016
+ 2017
+ 2018
+ 2019
+ 2020
+ 2021
+ 2022
+ 2023

Coding. Oh, my, v.6

Today I have learnt to create an elephant at the touch of a button. And to find Tor in a list. Not to mention the delight of turning a string into a list.

Confused? Me too.

I was especially discombobulated (I am taking refuge in friendly words) by Tor's assumption that I would know how f(x) worked (I associate it with differentiation and therefore with annoyance and pain, neither of which are conducive to happy learning).

Everything got much better once I managed to get him to admit that when he was talking about variables, he was really just talking about algebra (or at least algebra as it is defined in my brain; I always found it to be the friendliest branch of mathematics because it managed to avoid those pesky numbers, and I would ask you to not take this illusion away from me by explaining algebra beyond a high school level).

First thing's first: I set up my terminal to look cool. I instantly felt like a hardcore hacker.

We decided I should learn Python, because apparently Python is friendly and nice and will give me warm, cuddly feelings any moment now.

Tor then explained about functions and variables, and how variables can be anything from text strings (he seems obsessed with 'elephant' as a word -- I got much more excited when I realised text strings could include whole works of literature) to numbers (of all shapes and sizes -- I am less excited about them than about the text strings) and lists (which I rather like).

At first I was a little worried about keeping track of all of this, but things got a lot more fun once I realised that I could use actual words instead of single letters as variables: Words are much easier to direct when you call them word, rather than a or x.


for x in a:
    if x=='Tor':
        print x

is much more confusing and hard to keep track of than
for word in word_list:
    if word=='Tor':
        print word

I wrote

paragraph='I have always preferred books to computers, and my fear that the machine would die (possibly taking me with it) if I accidentally pushed the wrong sequence of buttons has entertained (and possibly frustrated?) Tor immensely. Much as I love technology that makes my life easier, I have had a (healthy) respect for the digital. You know where you stand with books. Unless you set fire to them or drop them in water, they will not accidentally get rid of your text; the worst they can do to you is give you a paper cut or fall on your head.'

which defined that text string (lifted from here) as the variable named paragraph. Then, I wrote
paragraph.split(' ')

which turned that paragraph into the following (slightly scary-looking) list:
['I', 'have', 'always', 'preferred', 'books', 'to', 'computers,', 'and', 'my', 'fear', 'that', 'the', 'machine', 'would', 'die', '(possibly', 'taking', 'me', 'with', 'it)', 'if', 'I', 'accidentally', 'pushed', 'the', 'wrong', 'sequence', 'of', 'buttons', 'has', 'entertained', '(and', 'possibly', 'frustrated?)', 'Tor', 'immensely.', 'Much', 'as', 'I', 'love', 'technology', 'that', 'makes', 'my', 'life', 'easier,', 'I', 'have', 'had', 'a', '(healthy)', 'respect', 'for', 'the', 'digital.', 'You', 'know', 'where', 'you', 'stand', 'with', 'books.', 'Unless', 'you', 'set', 'fire', 'to', 'them', 'or', 'drop', 'them', 'in', 'water,', 'they', 'will', 'not', 'accidentally', 'get', 'rid', 'of', 'your', 'text;', 'the', 'worst', 'they', 'can', 'do', 'to', 'you', 'is', 'give', 'you', 'a', 'paper', 'cut', 'or', 'fall', 'on', 'your', 'head.']

After which I saved this list as word_list by writing
word_list=paragraph.split(' ')

I could probably have done that without the intermediary step, but Tor was being pedagogical.

At which point,

for word in word_list:
    if word=='Tor':
        print word

became possible.

In other words: I can now search a text for words using only the power of my coding skills. You may worship me. (If anyone mentions that it is not a very good search because it can be thrown off by punctuation, you will not get any cake.)

And to make matters even more interesting: I can count each instance of the word by writing

for word in word_list:
    if word=='Tor':

I get a number! Instead of Tor written over and over.

Of course, this all depends on my ability to define things correctly, but while slightly daunting it is oddly familiar from writing academic texts.

I wonder whether I will remember any of this tomorrow.


Version 1

Camilla, 06.04.13 12:09

Version 2

Camilla, 06.04.13 14:12

Version 3

Camilla, 06.04.13 14:13

Version 4

Camilla, 06.04.13 18:08

Version 5

Camilla, 06.04.13 18:11

Version 6

Camilla, 04.06.13 10:26