How to list contents of deb file

The command is straightforward:

$ dpkg --contents foo.deb

Or a shorter version:

$ dpkg -c foo.deb

Tried with: Dpkg 1.17.5 and Ubuntu 14.04

How to list installed programs at commandline in Windows

To list all the installed programs at the commandline in Windows, use this command: wmic product

A lot of parameters are listed for every product. Some of the parameters are: name, description, URL, telephone number (not kidding!), ID, installed date, installed directory, source directory from which it was installed, language, name of installer file, vendor and version.

With so many parameters, the output for each prorgram simply cannot fit on a single line. So, it is better to redirect it to a file: wmic product > proglist.txt

Tried with: Windows 7 x64

How to use queue in Python

The ubiquitous list can be used as a queue in Python. But, that is not efficient because of the way lists are implemented.

Using deque from the collections module is a straightforward way to use queues:

# remove <– [….] <– insert
# Queue with insertion from right and removal from left
from collections import deque
q = deque()
# deque([])
q.append( 10 )
# deque([ 10 ])
q.append( 50 )
# deque([ 10, 50 ])
q.append( 30 )
# deque([ 10, 50, 30])
q.popleft()
# 10

view raw
queue.py
hosted with ❤ by GitHub

Tried with: Python 2.7.3

List comprehension in Python

A list comprehension is a convenient method to create lists in Python.

a = [ i for i in range( 5 ) ]
# [0, 1, 2, 3, 4]

a = [ i for i in range( 5 ) if 0 == ( i % 2 ) ]
# [0, 2, 4]

# In general any sequence of for and if
a = [ i for ... if ... for ... for ... if ... ]
a = [ i for i in range( 5 ) if 0 == ( i % 2 ) ]

# ... this is the same as ...

a = []
for i in range( 5 ):
    if 0 == ( i % 2 ):
        a.append( i )

Tried with: Python 3.2

Using list as queue in Python

The humble list can be used as a simple queue in Python.

q = []

for i in range( 0, 5 ):
    q.append( i ) # Add to back of queue

while q: # Queue not empty
    j = q.pop( 0 ) # Get from front of queue
    print( j )

# Output: 0 1 2 3 4

Note that popping the first item of a list is not optimal due to the way it is implemented. For large queues, using deque as queue is a much better option.

Tried with: Python 3.2.2