lwbco i am starting to see the light

mattseh

import this
Apr 6, 2009
5,504
72
0
A ~= A
I always suspected you were right about functional python, but stuff like this is pretty cool:

Code:
any((line.startswith('crawl') for line in open('file.txt')))
less code, less bugs, moar monies, still no need to learn ruby.
 


pure functions ftw

I'm not a great coder, but reading SICP def upped my game. After working through the first few chapters, I've rarely defined a function that depends on the program's state (a given input produces the same output everytime).

I need to dig into Python's functional tools more, but I do love me some list comprehensions.
 
writing this quick to GetItWorking (TM), but feels really inelegant, any suggestions?

Code:
        for line in page_content.split('\n'):
            line = line.strip()
            if len(line) and len(line.split(',') == 2) and line.split(',')[0].strip() in anchor_data:
                anchor_data[line.split(',')[0].strip()] = int(line.split(',')[1])
 
Code:
dict(map(lambda line: [line.strip().split(',')[0], int(line.strip().split(',')[1])], filter(lambda line: len(line.strip()) and len(line.strip().split(',')) == 2 and line.strip().split(',')[0].strip() in anchor_data, page_content.split('\n'))))

Problem?

trollface.jpg