TypeError: list indices must be integers, not str (boolean convertion actually)

Only change that needs to be made is that features must be initialized to a dict ({}) rather than a list ([]) and then you could populate it’s contents. The TypeError was because word_features is a list of strings which you were trying to index using a list and lists can’t have string indices. Here, the elements present in word_features constitute the keys of dictionary, features holding boolean values, True based on whether the same … Read more

Finding median of list in Python

How do you find the median of a list in Python? The list can be of any size and the numbers are not guaranteed to be in any particular order. If the list contains an even number of elements, the function should return the average of the middle two. Here are some examples (sorted for … Read more

What does “\r” do in the following script?

The ‘\r’ character is the carriage return, and the carriage return-newline pair is both needed for newline in a network virtual terminal session. From the old telnet specification (RFC 854) (page 11): The sequence “CR LF”, as defined, will cause the NVT to be positioned at the left margin of the next print line (as would, for example, the … Read more

Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries

You can change the property categorie of the class Article like this: and the error should disappear. Eventually you might need another option for on_delete, check the documentation for more details: EDIT: As you stated in your comment, that you don’t have any special requirements for on_delete, you could use the option DO_NOTHING:

Does Python have an ordered set?

There is an ordered set (possible new link) recipe for this which is referred to from the Python 2 Documentation. This runs on Py2.6 or later and 3.0 or later without any modifications. The interface is almost exactly the same as a normal set, except that initialisation should be done with a list. This is a MutableSet, so the … Read more

Get Color Palettes from ColorHunt.co in Python

I am creating a Color Addon for Blender And I am trying to retrieve color Palettes From Famous sites. I would like to start with ColorHunt. Basically as you can see on the site there are a lot of color palettes. I would like to get all the avaiable palettes in an array containing the HEX … Read more

if A vs if A is not None:

The statement will call A.__nonzero__() (see Special method names documentation) and use the return value of that function. Here’s the summary: object.__nonzero__(self) Called to implement truth value testing and the built-in operation bool(); should return False or True, or their integer equivalents 0 or 1. When this method is not defined, __len__() is called, if it is defined, and the object is considered true if its result is … Read more