Fix Python – How can I initialize a dictionary of distinct empty lists in Python?

My attempt to programmatically create a dictionary of lists is failing to allow me to individually address dictionary keys. Whenever I create the dictionary of lists and try to append to one key, all of them are updated. Here’s a very simple test case:
data = {}
data = data.fromkeys(range(2),[])
print data

Actual result: {….

Fix Python – Python: converting a list of dictionaries to json

I have a list of dictionaries, looking some thing like this:
list = [{‘id’: 123, ‘data’: ‘qwerty’, ‘indices’: [1,10]}, {‘id’: 345, ‘data’: ‘mnbvc’, ‘indices’: [2,11]}]

and so on. There may be more documents in the list. I need to convert these to one JSON document, that can be returned via bottle, and I cannot understand how to do this. Please he….

Fix Python – Custom Python list sorting

I was refactoring some old code of mine and came across of this:

def cmp_items(a, b):
if >
return 1
elif ==
return 0
return -1

The code works (and I wrote it some 3 years ago!) but I cannot find this thing documented anywhere in the Python docs and everybod….