Skip to content

Tag: python

pop/remove items out of a python tuple

I am not sure if I can make myself clear but will try. I have a tuple in python which I go through as follows (see code below). While going through it, I maintain a counter (let’s call it ‘n’) and ‘pop’ items that meet a certain condition. Now of course once I pop the first item,…

Sort dictionary by the INT value of the value

There are many posts here about sorting dictionaries in Python so I was careful to read them and hope this is not a duplicate: I’m using a dictionary to hold words as keys and the occurrence of the word as value. This leads to a dictionary that could be like: I want to sort them by occurrence (the &#821…

Python ‘list indices must be integers, not tuple”

I have been banging my head against this for two days now. I am new to python and programming so the other examples of this type of error have not helped me to much. I am reading through the documentation for lists and tuples, but haven’t found anything that helps. Any pointer would be much appreciated.…

Python DNS module import error

I have been using python dns module.I was trying to use it on a new Linux installation but the module is not getting loaded. I have tried to clean up and install but the installation does not seem to be working. $ python –version Python 2.7.3 $ sudo pip install dnspython Downloading/unpacking dnspython …

RuntimeWarning: divide by zero encountered in log

I am using numpy.log10 to calculate the log of an array of probability values. There are some zeros in the array, and I am trying to get around it using However, RuntimeWarning: divide by zero encountered in log10 still appeared and I am sure it is this line caused the warning. Although my problem is solved, …