Category: Python

  • Calling an external command in Python

    $pwd /home/jeffrin/beautifulwork/github $ls beautifulwork-github.php beautifulwork-github.py $ls -l total 8 -rw-r–r– 1 jeffrin jeffrin 414 Dec 10 2016 beautifulwork-github.php -rw-r–r– 1 jeffrin jeffrin 1300 Dec 10 2016 beautifulwork-github.py $cat ../../ls.py from subprocess import call call([“ls”, “-l”]) $python ../../ls.py total 8 -rw-r–r– 1 jeffrin jeffrin 414 Dec 10 2016 beautifulwork-github.php -rw-r–r– 1 jeffrin jeffrin 1300 Dec 10…

  • Tuples

    https://www.pythonlearn.com/html-008/cfbook011.html

  • Iterating over dictionaries using ‘for’ loops

    https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops

  • How to open a webpage and search for a word in python

    https://stackoverflow.com/questions/1913871/how-to-open-a-webpage-and-search-for-a-word-in-python

  • How to split a string into a list?

    https://stackoverflow.com/questions/743806/how-to-split-a-string-into-a-list

  • using the dir() Built-in function in Python programming

    >>> import struct >>> dir() # show the names in the module namespace [‘__builtins__’, ‘__doc__’, ‘__name__’, ‘struct’] >>> dir(struct) # show the names in the struct module [‘Struct’, ‘__builtins__’, ‘__doc__’, ‘__file__’, ‘__name__’, ‘__package__’, ‘_clearcache’, ‘calcsize’, ‘error’, ‘pack’, ‘pack_into’, ‘unpack’, ‘unpack_from’] >>> class Shape(object): def __dir__(self): return [‘area’, ‘perimeter’, ‘location’] >>> s = Shape() >>> dir(s)…

  • Looking into a few commands with python interactive shell

    ABOUT PYTHON Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.[26] Van Rossum led the language community until stepping down…

  • How to write a program to solve project Euler problem 4

    ”’ This file is worked on from http://www.s-anand.net/euler.html , Solution of Problem 4 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. Find the largest palindrome made from the product of two 3-digit numbers. ”’ n = 0 for…

  • Project Euler Problem 3, solution internals using python debugger

    $python -m pdb euler-three.py > /home/jeffrin/beautifulwork/lib/euler-three.py(7)() -> ”’ (Pdb) r 6857 –Return– > /home/jeffrin/beautifulwork/lib/euler-three.py(17)()->None -> print n (Pdb) next –Return– > (1)()->None (Pdb) next The program finished and will be restarted > /home/jeffrin/beautifulwork/lib/euler-three.py(7)() -> ”’ (Pdb) next > /home/jeffrin/beautifulwork/lib/euler-three.py(9)() -> n = 600851475143 (Pdb) next > /home/jeffrin/beautifulwork/lib/euler-three.py(11)() -> i = 2 (Pdb) next > /home/jeffrin/beautifulwork/lib/euler-three.py(12)()…

  • Project Euler Problem 2, solution internals using python debugger

    $python -m pdb project-euler-2.py > /home/jeffrin/beautifulwork/lib/project-euler-2.py(13)() -> ”’ (Pdb) next > /home/jeffrin/beautifulwork/lib/project-euler-2.py(15)() -> cache = {} (Pdb) next > /home/jeffrin/beautifulwork/lib/project-euler-2.py(16)() -> def fib(n): (Pdb) next > /home/jeffrin/beautifulwork/lib/project-euler-2.py(20)() -> n = 0 (Pdb) next > /home/jeffrin/beautifulwork/lib/project-euler-2.py(21)() -> i = 0 (Pdb) next > /home/jeffrin/beautifulwork/lib/project-euler-2.py(22)() -> while fib(i) /home/jeffrin/beautifulwork/lib/project-euler-2.py(23)() -> if not fib(i) % 2: n =…