Linked Questions

2 votes
2 answers
961 views

I would like to save a dictionary that contains both string and integer keys and multiple datatype values. For example: dData = { 'a': ['c','d'], 1: [5.1, 3.1] } To save and load it I used ...
Roman's user avatar
  • 9,501
1 vote
3 answers
1k views

I wanted to dump a dictionary into a json file, and later on, load it so then I would use it. dic = {} for n in range(1,10): if n%2==0: dic[n] = n**2 else: dic[str(n)] = n**2 ...
mahisafa82's user avatar
1 vote
1 answer
1k views

I have saved a dictionary as json to re-use later across a number of areas. The dictionary structure is: dict = { 1: 'Name', 2: 'Name2', 3: 'Name3' } I have saved it as so: with open('...
jbachlombardo's user avatar
-2 votes
3 answers
453 views

So this little snippet of code takes an array A of integers and makes the integers strings when they become the keys of pairs. Why? Python is happy for them to remain integers, but JavaScript seems ...
boatcoder's user avatar
  • 18.2k
262 votes
5 answers
279k views

Does there exist a way in Python 2.7+ to make something like the following? { something_if_true if condition else something_if_false for key, value in dict_.items() } I know you can make ...
diegueus9's user avatar
  • 32.1k
125 votes
11 answers
137k views

When I create a new JavaScript array, and use an integer as a key, each element of that array up to the integer is created as undefined. For example: var test = new Array(); test[2300] = 'Some string';...
user avatar
68 votes
4 answers
108k views

My question is very similar to this one, except I have a dictionary of lists and I'm interested in changing both the key value and all elements in every list form string to int. So for instance I'd ...
Matteo's user avatar
  • 8,172
54 votes
2 answers
14k views

Are there any known ways for ast.literal_eval(node_or_string)'s evaluation to not actually be safe? If yes, are patches available for them? (I already know about PyPy[sandbox], which is presumably ...
user avatar
44 votes
3 answers
33k views

According to this conversion table, Python ints get written as JSON numbers when serialized using the JSON module--as I would expect and desire. I have a dictionary with an integer key and integer ...
jveldridge's user avatar
  • 1,085
11 votes
2 answers
10k views

It is well known that json converts integer keys of a dict to string: import json print json.dumps({1: [2.5, 2.5, 2.5], 2: [3, 3, 3, 3]}) # {"1": [2.5, 2.5, 2.5], "2": [3, 3, 3, 3]} What's the ...
Basj's user avatar
  • 47.5k
6 votes
4 answers
4k views

I was trying to serialize my objects in a way that I could read them in the external form and found jsonpickle. But it turns out that it converts my dictionary keys from integers to strings. I ...
AlanObject's user avatar
0 votes
2 answers
4k views

In my program, I have certain settings that can be modified by the user, saved on the disk, and then loaded when application is restarted. Some these settings are stored as dictionaries. While trying ...
Justin8051's user avatar
3 votes
2 answers
2k views

The pandas to_json function for some reason is converting the index of the dataframe into strings. Is there a way to avoid this? >>> import pandas as pd >>> df = pd.DataFrame({"a" : ...
Alex's user avatar
  • 4,314
2 votes
3 answers
2k views

The JSON equivalent of a Python dict is a JSON object. However its keys must be strings, that's a well-known limitation. I need to support also boolean and numeric keys. I could make a simple Python ...
VPfB's user avatar
  • 18.1k
0 votes
2 answers
60 views

I have a command where you can enter a correct answer. If it is correct, the user is credited with points in a JSON. But my update function seems to be broken, because after another correct execution ...
Dominik's user avatar
  • 3,582